ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: rgorantla on August 02, 2017, 12:15:57 am
-
1. Save State and load State from database:
I am trying to save and load columns /Column Model to and from Database on to the Grid.Also, after re-ordering - would like to save it to database.
Local storage is working fine but not database.
2. show/hide columns : when we select a column to hide or unhide can we push those to the end
-
1. Please share a test case.
2. yes. colModel can be manipulated like an ordinary array and array methods i.e., splice/ push can be used to move the columns the way you need.
Just remember to call grid.refreshCM() and grid.refresh() after that.
-
- Can you provide me an example of how the col model should be when saving to database and how ?
second question - yes i was using push but whenever i show/hide columns - they are appearing in the order of how col model is defined but not to the end
-
1. In case of database storage of state, it would remain same as https://paramquery.com/pro/demos/grid_state except the part where saveState and loadState is called.
Instead of simple grid.saveState()
var state = grid.saveState({save: false}); //returns state string.
//post state string to remote store via Ajax call $.ajax
Instead of simple grid.loadState()
//get state string from remote store via Ajax call $.ajax
and call grid.loadState({state: state}); in Ajax success callback.
2. Please share a test case of your implementation.
-
for the 1st one : Thank you, but i still have a an issue - i will send a sample
2. its the same as how it works in your demo. https://paramquery.com/pro/demos/showhide_columns . Instead of adding it in the order of the colmodel definition - can we show at the end. ?
-
2. Yes as mentioned earlier colModel is a simple array, so it can be manipulated like one.
To move the items in an array,
a. remove items from their original location with splice().
b. place them at a new location ( in your case at the end ) with push().
and call grid.refreshCM() and grid.refresh() after that.
-
hi,
2nd point got it to work . Thanks!
1st point : I think i got it to work but state is having only few properties but not all properties. For ex : for Order Id i have class etc.. but all i see in the state is
{"colModel":[{"width":50,"dataIndx":"OrderID","filter":{}} ..Please let me know what else should i add to get this to include all properties - The reason i am asking is to get the complete colModel from database,
-
state doesn't have the complete colModel, it's not meant for that.
if you need to serialize complete colModel, then use JSON.stringify ( complete colModel ) but please note that JSON.stringify discards any inline functions.