Announcement

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

    ListGrid Sequence

    I am using SmartGWT 2.4 and would like to have a grid that includes a field that displays the row number. I realize I can turn on setShowRowNumbers but I also need this row number sequence to be stored in my database. The grid will also allow drag and drop from external components as well as internally in order to reorder records. I would like the row number field to auto-renumber from 1 to x in those situations. I have tried adding an onDrop event handler that loops through the ResultSet and manually sets this value but it appears the sequence of records returned by the index is not in the new order (ie after the drop).
    Any suggestions?

    #2
    I'm running into the same thing.
    I've tried putting a loop into the onRecordDrop handler but it doesn't seem to be changing the fields in the ListGrid's records.

    Comment


      #3
      I did this - but simulated like this:
      I sort the grid on that internal sequence number (so I don't offer the user to order the grid).

      grid.getRecords() should give you the records in the on-screen order, not in the resultset order.

      onRecordDrop event gives you the event.getIndex() where the user dropped the record.

      All records before that index remain untouched.
      On all records after that, I add 1 to their sequence number.
      Then I manually resort the grid on that internal sequence number, so the new record is shown in its expected place.

      I didn't want to use row numbers, because there might be gaps in the sequence number (e.g. because of a remove).

      Comment


        #4
        When I send records from the datasource to the grid I assign sequential values to a 'sequence' field.
        I then do a drag-reorder.
        I use grid.getRecords() and iterate through them and assign them new values in their 'sequence' field. Unfortunately, when my datasource receives the update call the sequence values are in the original order.
        Code:
                    @Override
                    public void onRecordDrop(final RecordDropEvent aEvent)
                    {
                        final ListGridRecord rec = getRecord(aEvent.getIndex());
                        for (int index = 0; index < getRecords().length; index++)
                        {
                            final Record curr = getRecord(index);
                            curr.setAttribute("sequence",
                                              index);
                            updateData(curr);
                        }
                        saveAllEdits();
                    }
                });
        Last edited by evanross; 24 Oct 2011, 09:37.

        Comment


          #5
          I'm dealing with a similar issue. The order of the records in the listgrid matters, and I have a field to store that order in the database. It would be nice to be able to just renumber everything in the grid after the drop event finishes adding or reordering, but it seems that requires canceling the event and writing the whole add/reorder routine manually, finishing with a callback from the update of the datasource.

          Does anyone know a way to act on the finish of a datasource update that comes from the default drag-copy or drag-reorder behavior of a listgrid? Like being able to specify a callback from the default behavior. Is there an eventhandler for this event that I am just missing?

          Comment


            #6
            @evanross when you directly change something on a Record, you're changing the client-side cache. Instead create a new Record with just the primaryKey from the original record and the single field you want to update. This is also cleaner since you're not telling the server that this user wants to save all the values in the record, some of which could have been changed by other users in the meantime.

            @revmen you seem to think this is a lot of code, it isn't. Save the new indices and call sort() when your save completes.

            Comment


              #7
              Originally posted by Isomorphic
              call sort() when your save completes.
              This is what I'm asking about. I can't figure out how to execute code in response to the completion of the save. I'm wondering if there's some kind of RecordDropCompletion event or something to that effect.

              Comment


                #8
                When *you* do the save, you have the callback from eg updateData() to work with. Since reordering records according to a persistent order field is not a built-in function of drag and drop, you need to do the save anyway.

                Comment


                  #9
                  Gotcha. Thanks.

                  Comment

                  Working...
                  X