Announcement

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

    ClientOnly DS remove and add data operation

    Hi,

    I am trying to refresh a listgrid without flicker. For this reason I have implemented a listgrid with a clientonly datasource. On refresh I am using a duplicate datasource without the clientOnly flag and then adding/updating/removing data as needed. However on refreshing the listgrid I get the following error:

    clientOnly remove operation failed .. missing primaryKey value(s):myKey

    or

    add operation failed .. duplicate key in record

    Code:
     
    
    dataSource.fetchData(null, new DSCallback() {
                @Override
                public void execute(DSResponse response, Object rawData, DSRequest request) {
    
                    ArrayList newKeyList = new ArrayList();
                    Record[] recordList = response.getData();
                    ResultSet rs = listGrid.getResultSet();
    
                    //add and update
                    for (int m = 0; m < recordList.length; m++) {
                        Record rec = recordList[m];
    
                        String key = rec.getAttribute("myKey");
                        newKeyList.add(key);
    
                        if (rs.findByKey(key) != null)
                            listGrid.updateData(rec);
                        else
                            listGrid.addData(rec);
                    }
    
    
                    //remove
                    for (int m = 0; m < rs.getLength(); m++) {
                        Record rec = rs.get(m);
                        if (!newKeyList.contains(rec.getAttribute("myKey")))
                            listGrid.removeData(rec);
                    }
                }
    
            });
    Any pointers why these errors are coming? They are fairly reproducible with a large dataset. They primary key is declared to be unique in the datasource.

    Thanks for your help!

    #2
    The correct way to do background refresh of a grid is shown here (we're not looking at why you'd get errors).

    Comment


      #3
      Initially I used the approach you suggested, but I had issues if the client selected a row. The selection used to disappear for a few seconds and then reappear after refresh. In addition I had issues maintaining clientside filtering after refresh.

      Comment

      Working...
      X