Search code examples
gxt

Preserve Selection when Scrolling GXT


I am using Sencha GXT Grid for a web app. But what I see is after scrolling the grid the selection is gone. I tried to preserve the selection by catching the scroll event and restoring the selected items (using setsecteditems() ). But was not successful also. Is there a method to preserve the selection in sencha GXT grid. Thanx


Solution

  • I have finally able to preserve the selection in Live grid view. I found two ways that I thought worth to share.It's kind of a hack :) 1. If you are receiving data from a server. You can maintain a boolean in server side data preserving the selection. and when you render rows in the client side you can add a style name to that row checking the boolean which is set previously. the style name can be set using

     grid.getView().setViewConfig(new GridViewConfig() {
    
            @Override
            public String getColStyle(Object model, ValueProvider<? super Data, ?> valueProvider, int rowIndex, int colIndex) {
                return null;
            }
    
            @Override
            public String getRowStyle(Objectmodel, int rowIndex) {
                //Do the logic here and return the Style name  
                return null;
            }
        });
    
    1. You can also maintain a list of keys in client side which contains the selected items. and use the previous method to add a style name if the row you are drawing is in the list. Thanx :)