Announcement

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

    How to get the changed records from a DataChangedHandler?

    I have a ListGrid that uses a given DataSource with an attached ResultSet. The details for the selected record from the ListGrid are presented within a separate panel. I need to detect the changes and adjust the details panel but only if the selected record has changed. If other records changed I do not need to do anything:
    Code:
            ResultSet template = new ResultSet();
            template.setDataSource(AssignmentDataSource.getInstance());
            template.addDataChangedHandler(new DataChangedHandler() {
                @Override
                public void onDataChanged(DataChangedEvent event) {
                    if (assignmentsGrid.getSelectedRecord() == null) {
                        // TODO disable details panel
                    } else {
                        // TODO test if the changed record is the selected record
                    }
                }
            });
    
            assignmentsGrid = new MyAssignmentsGrid();
            assignmentsGrid.setDataProperties(template);
    The question is how do I get the changed record to compare it with the selected record from the grid?

    Thank you,
    Tiberiu

    #2
    If you only care about the selected record, take a copy when it becomes selected, and compare to the current selected record when a data change occurs.

    Comment


      #3
      Hmm... that might do the trick in this particular case. But for a more general case when you just want to get the changed record and do something with it wouldn't it be useful to have a method in DataChangedEvent like getChangedRecord() or something like that?

      Comment


        #4
        DataChanged can signal multiple changes to different records, as well as no change to any record, but instead a refresh of the dataset or a change in criteria causing new data to be loaded. So a getChangedRecord() API doesn't really make sense on this particular notification.

        To react to more specific scenarios, such as a single record update, consider APIs such as DataSource.transformRequest/transformResponse.

        Comment


          #5
          Originally posted by Isomorphic View Post
          If you only care about the selected record, take a copy when it becomes selected, and compare to the current selected record when a data change occurs.
          Trying to use the workaround mentioned by you I got into the situation when the selection is lost hence I can not do the above compare. More exactly the selection is lost after an update for a list of records but it is not lost after an update for just one record. Is this a feature or a bug?

          Using SmartClient Version: SNAPSHOT_v10.1d_2015-09-22/LGPL Development Only (built 2015-09-22)

          Please find attached a sample test case to better understand what I mean.
          Attached Files

          Comment


            #6
            Ignore the above. I found the answer at http://forums.smartclient.com/forum/...n-updatecaches

            Comment

            Working...
            X