Author Topic: saveState filterModel  (Read 3947 times)

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
saveState filterModel
« on: December 25, 2018, 08:38:40 pm »
Hello,
How do I save the filter model to "saveState"?

I have to open it again when the page opens.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: saveState filterModel
« Reply #1 on: December 26, 2018, 07:12:39 pm »
Filter values and conditions are saved in columns. It's enabled by default and configurable through stateColKeys option.

https://paramquery.com/pro/api#option-stateColKeys

https://paramquery.com/pro/demos/grid_state
« Last Edit: December 26, 2018, 07:14:13 pm by paramquery »

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: saveState filterModel
« Reply #2 on: December 26, 2018, 09:16:47 pm »
I beg your pardon. I tried it right now, but it didn't. Can you give sample code? What can I do?

Code: [Select]
,stateColKeys:{filterModel:1}

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: saveState filterModel
« Reply #3 on: December 26, 2018, 09:50:46 pm »
I've added this code.

Code: [Select]
,stateKeys : {filterModel:['header','on','mode','type','timeout']}

In "Storage", I see "header true".

But "header" is not open.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: saveState filterModel
« Reply #4 on: December 27, 2018, 12:04:32 pm »
There is inbuilt support to restore only existing default models ( groupModel, pageModel & sortModel in stateKeys ) via loadState.

filterModel can be added in localStorage via stateKeys but loadState can't restore it automatically.

you might need to read filterModel from localStorage directly and update filterModel of grid.

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: saveState filterModel
« Reply #5 on: December 27, 2018, 12:39:08 pm »
...you might need to read filterModel from localStorage directly and update filterModel of grid.

I don't know how to do that. I will try to make it.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: saveState filterModel
« Reply #6 on: December 27, 2018, 02:56:53 pm »
Please use this

Code: [Select]
create: function () {
//restore state of grid.                               
                this.loadState({
refresh: false
});

var state = JSON.parse(localStorage.getItem("pq-grid"+this.element[0].id ));
this.option('filterModel.header', state.filterModel.header);
},

omerix

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 148
    • View Profile
Re: saveState filterModel
« Reply #7 on: December 28, 2018, 12:38:20 pm »
Thanks Param.

Works very well

Code: [Select]
this.loadState({refresh: false});
var state = JSON.parse(localStorage.getItem("pq-grid"+this.element[0].id));
if (state!=null) {
console.log(this.element[0].id);
this.option('filterModel', state.filterModel);
this.option('menuIcon', state.menuIcon);
};