Author Topic: Save column state with refreshDataAndView  (Read 2237 times)

shldbapp

  • Pro Enterprise
  • Newbie
  • *
  • Posts: 5
    • View Profile
Save column state with refreshDataAndView
« on: September 25, 2015, 06:13:52 pm »
What is the correct way to combine the (working) code below and the $grid.pqGrid("refreshDataAndView") function?
When using the refreshDataAndView function the column sorting state is not working.
 
Code: [Select]
//setter
            var CM = $grid.pqGrid("option", "colModel");
            var strCM = JSON.stringify(CM);
            $.cookie("CM", strCM);
            //alert(strCM);
  //getter
            var strCM2 = $.cookie("CM");
            alert(strCM2);
            var CM2 = JSON.parse(strCM2);
            $grid.pqGrid("option", "colModel", CM2);
            $grid.pqGrid("refresh");

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Save column state with refreshDataAndView
« Reply #1 on: September 28, 2015, 08:13:36 am »
this code is to get and set colModel in a cookie, it doesn't preserve the sort state of the grid.

Couple of points:

1. sort state is stored in dataModel.sortIndx, dataModel.sortDir in version 2.x while it's stored in sortModel in version 3.x so you might need to store these variables besides colModel.

2. HTML5 localStorage could be used instead of cookie as cookies have less storage capacity.

3. Version 3 has inbuilt ability to store and restore the state of the grid via API saveState and loadState. It could be used directly instead of writing code.

http://paramquery.com/pro/demos/grid_state.