:: Forum >> Version 2 >>

Maintaining sort after grid refresh.

I am using v2b3.

I am developing an app that updates the grid data in the background asynchronously. I would like to keep the grid sorting across a call to Grid.refresh(). I've tried using set/getSortModel(), but the model doesn't seem to updated when the user clicks on the grid header to sort. Most likely I am doing something wrong.
LostInSpace
Thursday, December 1, 2005
Found my own answer: perhaps someone else can benefit:

// get sort properties
var sortColumn = grid.getSortColumn();
var sortDirection = grid.getSortDirection(sortColumn);

// refresh grid
grid.clearRowModel();
grid.setRowCount(model.getCount());
grid.refresh();

// reinstate sorting
if (sortColumn != -1) {
grid.sort(sortColumn, sortDirection);
}
LostInSpace
Thursday, December 1, 2005
LostInSpace, I was having the same problem, and your solution worked. Thank you!
LanceH
Thursday, May 4, 2006
Hmm, I'm really having problems getting this working and was wondering if anyone had any ideas...

function getData(url) {
    
data.setURL(url);
    
data.request();
  }

  function 
resortData() {
    
// get sort properties
    
var sortColumn table.getSortColumn();
    var 
sortDirection table.getSortDirection(sortColumn);
 
    
// refresh grid 
    
table.clearRowModel();
    
table.setRowCount(data.getCount());
    
table.refresh();

    
// reinstate sorting
    
if (sortColumn != -1) {
      
table.sort(sortColumnsortDirection);
    }
  }

  function 
reloadData() {
    var 
url;                                                                             
    var 
= new Date();                                                                  
    var 
tab tabs.getSelectedItems();                                                   
    var 
type 'all';                                                                    
      if (
tab == 1)                                                                        
        
type 'my';                                                                       
      else if (
tab == 2)                                                                   
        
type 'chronic';                                                                  
                                                                                             
    
url data_url type +"&" d.getTime();                                            
                    
    
getData(url);
    
resortData();
    
self.setTimeout(reloadData$reload_time 1000);                                        
  }               
Mike
Friday, June 30, 2006



This topic is archived.

Back to support forum

Forum search