Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Recommended way of checking for duplicates after drag+drop?

    Hello,

    When dropping an employee in the teammember grid, like in the example of http://www.smartclient.com/smartgwtee/showcase/#row_drag_save , what is the recommended way to prevent duplicates in the team (in the example this is not checked by the way)?

    I could think of a few approaches. Is it for instance best to put a key/unique index on some database columns, and let the query fail, then somehow handle this?

    Or do this check locally, and do a set union, and only save the ones that are not in the target set already (ie. ignoring the other ones, which seems the most user-friendly way).

    Or both?

    I am asking this because I am thinking about implementing some stuff like this using drag'n'drop, and want to discuss some approaches.

    #2
    The best way to prevent duplicates is to setPreventDuplicates(true) - take a look at the docs for the approach it takes.

    It's intended to be set in that sample - the sample will be corrected.

    Comment


      #3
      I used setPreventDuplicates(true) on the target grid, but it does not help. I do have the following situation (quoted from the docs, ie. the link you provided):
      For DragDataAction:"copy" where the target DataSource is related to the source DataSource by foreignKey, a duplicate means that the target list, as filtered by the current criteria, already has a record whose value for the foreignKey field matches the primaryKey of the record being transferred.

      For example, consider dragging "employees" to "teams", where "teams" has a field "teams.employeeId" which is a foreignKey pointing to "employees.id", and the target grid has search criteria causing it to show all the members of one team. A duplicate - adding an employee to the same team twice - is when the target grid's dataset contains an record with "employeeId" matching the "id" field of the dropped employee.
      This is my situation, but it does not check for duplicates it seems. Note that the target grid in my case also has a primaryKey defined (to easily enable the deletion, ie to delete employees from a team), does this get precedence? This would explain things, since a unique teammemberId is created (using mysql's auto_increment for example) when something is dropped in it, and this means that there are never duplicates from the system's perspective.

      My datasources, source and target respectively:
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <DataSource ID="Hobby" serverType="sql" tableName="Hobby"> 
        <fields> 
          <field name="Hobby_id" type="sequence" primaryKey="true"/>  
          <field name="Name" title="Name" type="text" required="false" length="128"></field>  
        </fields> 
      </DataSource>
      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <DataSource ID="Person2Hobby" serverType="sql" tableName="Person2Hobby"> 
        <fields> 
          <field name="id" type="sequence" primaryKey="true"/>  
          <field name="Person_id" type="integer" foreignKey="Person.Person_id"/>  
          <field name="Hobby_id" type="integer" foreignKey="Hobby.Hobby_id"/>  
        </fields>  
      </DataSource>
      Of course, in my case there is the difference that this table is many-to-many, ie. it has TWO foreignKey's defined. Does this make a difference for your algorithm?

      Comment


        #4
        From a brief inspection, it seems like this case should be handled too, or that a flag could be added indicating that duplicate prevention should be applied in this case. This will mostly likely be looked at after a couple of weeks. If you need a quicker resolution you probably want to add your own duplicate prevention for this case, or consider getting a support contract.

        Comment


          #5
          Okay thanks.

          Comment

          Working...
          X