ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: omerix on January 22, 2014, 04:18:38 pm
-
Hello,
I am changing column's sizes and places. However when the page is refreshed they turns back to original size and places. Can you please advice if I those adjustments could be hold in cookies on your grid code?
-
You can serialize the colModel into string upon column resize or page unload event and save it in cookie and retrieve later upon grid reload.
var CM = $grid.pqGrid( "option", "colModel" );
var strCM = JSON.stringify( CM );
//save strCM in a cookie.
use $.parseJSON to convert string back to colModel.
There is no inbuilt API for cookie read / write in pqGrid. You could use some third party library
http://stackoverflow.com/questions/1458724/how-to-set-unset-cookie-with-jquery
http://www.sitepoint.com/eat-those-cookies-with-jquery/
-
Hello Param,
I'm include "<script src="js/jquery.cookie.js"></script>"
Where do you think the problem. Can you help?
Thanks
add code
var CM = $grid.pqGrid("option", "colModel");
var strCM = JSON.stringify(CM);
console.log(strCM);
$.cookie("test2",strCM,{json:true}); /* Not work */
var TestColMod1 ="[{\"Test\":\"Test String\"}]";
$.cookie("test3",TestColMod1,{json:true}); /* work */
strCM
[{"title":"ID","dataIndx":"Id","width":10,"dataType":"integer","editable":false,"align":"center","sortable":true,"hidden":true,"colSpan":0,"childCount":0,"leftPos":0,"rowSpan":1},{"title":"Uye","dataIndx":"UyeId","width":10,"dataType":"integer","editable":false,"align":"center","sortable":true,"hidden":true,"colSpan":0,"childCount":0,"leftPos":1,"rowSpan":1},{"title":"Yetki","width":150,"dataIndx":"ModulId","dataType":"integer","editable":true,"align":"left","sortable":true,"editor":{},"colSpan":1,"childCount":0,"leftPos":2,"rowSpan":1},{"title":"Yetki A
-
Here is the working code. You don't need to mention { json: true} as you are storing it as string in the cookie.
//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");
-
Thank you param,
Incredible very good