Forum


10:14

18/08/2009

Howdy All,
I'm attempting to save users column choices from the the Column Chooser to a cookie. Here's the snippet of code I'm using:
done : function (perm) {
if (perm) {
this.jqGrid("remapColumns", perm, true);
var cookieColumns = $("#list").getGridParam("colModel");
$.cookie("columns", cookieColumns, { expires: 365 });
}
}
});
This snippet itself is working fine. The probelm I run into is when I try to load value of the cookie into the colModel, I'm getting the standard error:
After doing some debugging, what I'm noticing is that the *.getGridParam("colModel") picks up a "rn" column, which is because I have row numbering turned on. So when I do something like this to load the cookie into the colModel:
if($.cookie("columns")) {
return $.cookie("columns");
} else {
return staticColumns;
}
}
and then:
I'm picking up an extra column (rn) that is causing the error above.
Is there any way I can easily get around picking up the 'rn' column when using getGridParam("colModel") so I can store and retrieve this info via cookie? I apologize in advance if this is more of a JavaScript question and not entirely related to JqGrid.
Thanks!
12:26

Moderators
30/10/2007

Hello,
In order to do this you should use a
var cookieColumns = $(”#list”).getGridParam(”colModel”);
var cookieNames = $(”#list”).getGridParam(”colNames”);
if(this.p.rownumbers) {
cookieColumns.splice(0);
cookieNames.splice(0);
}
….
or simple use label option in colModel of place of the colNames – in this case you will need to splice only the cookieColumns
Something similar is done in grid.import.js – see jqGridExport method.
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
01:16

18/08/2009

Hi Tony,
Thank you very much for taking the time to respond.
So in order to save the users preference of viewable columns to a cookie, would it be best to use the jqGridExport and jqGridImport methods instead of the approach listed above?
Thanks again!
Side Note: I played with the jqGridExport method yesterday using Firebug and was able to export the current state of my grid. One thing I noticed though is that the ColModel and ColNames arrays were both empty. Is this correct? If so, I'm not sure how using the export method would help me save a users column layout to a cookie. I'm probably just missing something(?)...
19:11

Moderators
30/10/2007

Hello,
This is not correct with the export. Which version do you use?
Also remember cookie are with limited size (could not remember how - but not so much)
Also the correct my code above should be:
var cookieColumns = $.extend([],$(”#list”).getGridParam(”colModel”));
var cookieNames = $.extend([],$(”#list”).getGridParam(”colNames”));
if(this.p.rownumbers) {
cookieColumns.splice(0);
cookieNames.splice(0);
}
….
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
19:24

18/08/2009

Hi Tony,
I'm using 3.6.1. I will look into the cookie size issue as well. Thanks for pointing this out. By the way, when I run the following in Firebug after my grid has loaded, I get the following:
"{"grid":{ "url":"jqGridCrudHw.php", "height":600, "page":1, "rowNum":25, "records":250, "pager":"#pager", "pgbuttons":true, "pginput":true, "colModel":[], "rowList":[ 25, 100, 500 ], "colNames":[], "sortorder":"asc", "sortname":3,.......
Notice that 'colModel' and 'colNames' are empty. Not sure this helps with anything but I thought I'd at least show you what I was seeing.
19:27

Moderators
30/10/2007

HEllo,
Could you please try with 3.6.2 - Also the export maybe work OK in IE - is this right?
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
19:49

18/08/2009

Ok, I will install 3.6.2 and see what happens.
I just ran 'jQuery(”#list”).jqGridExport({”exptype”:”jsonstring”})' in Companion.JS in IE and sure enough both colModel and colNames arrays were populated correctly. Does that mean that the jqGridExport method (at least in 3.6.1) does not work with Firefox?
Thanks again
By the way, I just upgraded to 3.6.2, reloaded my grid in FF and ran jqGridExport again. There is still no data in the colModel or colNames arrays.
11:35

Hi Tony/Mryle,
i was just going through this post. Well i want to dynamically add columns to my grid (the column names will come from a dropdown in my page,so i cannot hardcode the column names as it may change anytime ).Can i use yhis piece of code to add columns dynamically in my grid.
Please reply.
Thanks.
Sourav(Vik)
21:32

Moderators
30/10/2007

@mryle
Could you please try the last one from GitHub. I have done more on this. Thanks
@vik
Could not understand really Why not try
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
01:10

18/08/2009

Hi Tony,
Ok. I downloaded the current Development code from GitHub and create a development instance of my app. I went loaded my grid, which by the way loaded without error, made sure it was referencing the development code correctly and then ran:
in Firebug wtihin FF. The 'colModel' and 'colNames' arrays still are showing up empty in the output in Firebug:
I ran the same command using Companion.JS in IE and the 'colModel' and 'colNames' arrays are populated correctly.
Thanks again for the help...I'll keep working it from my end to see if I can come up with a different approach to store the visible columns in a cookie. Let me know if you have any other ideas.
19:40

Moderators
30/10/2007

Hello,
Thanks for the feedback. This is very interesting. In order to resolve the problem I need a link to the problem.
I have try diffrent girds with diffrent configuration and the export for me work OK simulating your command.
Thanks
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
21:33

18/08/2009

Howdy telubeer,
I'm relatively new to this level of complexity in JavaScript but I'm guessing that what you are doing is using Google Chrome's equivalent to Firebug and that you're finding a bug in the grid.import.js file. Am I correct? Is this something I should be changing in the library myself or was this just a note to Tony?
Thanks,
mryle
17:36

30/07/2009

So yes, it is a bug. The problem is that splice has two /required/ parameters. The first is the index of the point to insert/delete, and the second is the number of elements to delete. (Subsequent parameters are elements to be inserted after the deletes have taken place)
I'm guessing that most browsers treat the single parameter case as "delete 1", but chrome treats it as "delete to end of array".
Since omitting the second parameter is an error, either behavior is allowed.
So a simpler (and probably more efficient) fix would be to change it to splice(0,1);
Mark
17:56

Moderators
30/10/2007

Mark,
Thanks. Fixed.
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
55 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66