Announcement

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

    ListGrid sorting after new record is added

    Info: SmartGWT 3.0 pro nightly, FF 13

    I'm trying to do something quite simple but I can't get the hang of it.

    I have a SQLDataSource bound ListGrid that is automatically showing new records that are added into the DB by an associated DynamicForm. This works as expected: the new row is added into the database, however the new record is added to the top of the ListGrid.

    The ListGrid is set to have sorting done like this:
    Code:
    grid.setSort(new SortSpecifier[]{
    	new SortSpecifier("surname", SortDirection.ASCENDING),
    	new SortSpecifier("firstname", SortDirection.ASCENDING)
    });
    I guess there is some gap in my understanding - I would have thought that the ListGrid knowing that the DataSource's ResultSet was updated that it would sort the results for displaying.

    Another thread mentioned attaching to the DataChanged event on the ResultSet via setDataProperties to do a scrollToRow (which is what I want to do next). However I'm not sure how to sort from within the DataChanged event as calling a sort directly there has no effect, as I assume the record hasn't been drawn on the grid yet. The DataChanged event also doesn't seem to expose the changed records, so we would have to obtain a copy of the record before calling getRecordIndex and scrollToRow?
    Last edited by sunnyl; 13 Jul 2012, 00:44.

    #2
    There's no automatic re-sort() because that would potentially cause edited records to pop out of the viewport. Likewise automatically scrolling to show updated records would be the wrong thing much of the time.

    DataChanged is the right event to use, call resort() from there. If that seems to have no effect, try using DeferredCommand/Schedule to wait momentarily - this should not in theory be necessary, but if you're seeing no reaction to resort() this would probably fix it.

    findRecord() will get you the newly added record without a need to manually iterate. See also the many find*() methods on RecordList.

    Comment

    Working...
    X