3.2.0

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
December 1,
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
December 1,
LostInSpace, I was having the same problem, and your solution worked. Thank you!
LanceH
May 4,
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(sortColumn, sortDirection);
    }
  }

  function reloadData() {
    var url;                                                                             
    var d = 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
June 30,

This topic is archived.

See also:


Back to support forum