Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Jay on Nov 27, 2009 08:08
open dhtmlx forum
Resolve sorting order when filtering

Dear Sir or Madam,

in the article http://www.dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=10966&ssr=yes&s=Sorting%20filter
the Support writes the following:

"a) please be sure that sortRows is called before filterBy ( after first filtering, grid will lock original row order and will reuse it for next filtering - it can be resolved if necessary )"

I would like to know, how I can resolve the locked row order for the next filtering, so that the filtering is kept every time, if I filter?

To make it more clear:

I have 4 columns in my grid. The initial sorting is by 2nd and then by 1st column. If I filter just after the init and then go back to all rows, and then change the sorting, for example by 3rd column, I want that after the next filtering it has the last sorting order (3rd column). Actually it always get's the sorting order, which the first filtering process had locked.


Jay

Answer posted by dhxSupport on Nov 30, 2009 02:59
To restore sorting on the 3rd column after filtering you can use "onFilterEnd" event and getSortingState() method. getSortingState() method returns array, first element is index of sorted column, second - direction of sorting (“asc” or “des”). http://dhtmlx.com/dhxdocs/doku.php?id=dhtmlxgrid:api_method_dhtmlxgridobject_getsortingstate

mygrid.attachEvent("onFilterEnd",function(elements){
var sorting=mygrid.getSortingState();
  if (sorting.length){
      mygrid.sortRows(sorting[0],sorting_type,sorting[1]);//restore sorting after filtering was finished.
      mygrid.setSortImgState(true,sorting[0],sorting[1]);
}
 })