Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
getGridParam("colModel")
23/12/2009
10:14
Avatar
mryle
Member
Members
Forum Posts: 8
Member Since:
18/08/2009
sp_UserOfflineSmall Offline

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:

jQuery("#list").jqGrid('columnChooser', {
        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:

Length of colNames <> colModel!

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:

function returnColModel() {
    if($.cookie("columns")) {
        return $.cookie("columns");
    } else {
        return staticColumns;
    }
}

and then:

colModel: returnColModel(),

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!

26/12/2009
12:26
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

13/01/2010
01:16
Avatar
mryle
Member
Members
Forum Posts: 8
Member Since:
18/08/2009
sp_UserOfflineSmall Offline

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(?)...

13/01/2010
19:11
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

13/01/2010
19:24
Avatar
mryle
Member
Members
Forum Posts: 8
Member Since:
18/08/2009
sp_UserOfflineSmall Offline

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:

>>> jQuery("#list").jqGridExport({"exptype":"jsonstring"})

"{"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.

13/01/2010
19:27
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

13/01/2010
19:49
Avatar
mryle
Member
Members
Forum Posts: 8
Member Since:
18/08/2009
sp_UserOfflineSmall Offline

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.

14/01/2010
11:35
Avatar
vik
Guest
Guests

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 Yell).Can i use yhis piece of code to add columns dynamically in my grid.

Please reply.

Thanks.

Sourav(Vik)

14/01/2010
21:32
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

@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 Wink

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.

15/01/2010
01:10
Avatar
mryle
Member
Members
Forum Posts: 8
Member Since:
18/08/2009
sp_UserOfflineSmall Offline

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:

jQuery("#list").jqGridExport({"exptype":"jsonstring"})

in Firebug wtihin FF.  The 'colModel' and 'colNames' arrays still are showing up empty in the output in Firebug:

"{"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, "datatype":"json", "mtype":"POST",....

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.

15/01/2010
19:40
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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/01/2010
07:30
Avatar
telubeer
Guest
Guests

tonytomov-jqGrid-5fae4e1
lets “manual jqGridExport”
google-chrome console:
in:$('#s1list').jqGrid('getGridParam','colModel');
out:[Object,Object,Object]
in:var op=$('#s1list').jqGrid('getGridParam','colModel')
out:undefined
in:op
out:[Object,Object,Object]
in:op.splice(0);
out:[Object,Object,Object]
in:op
out:[]
in:$('#s1list').jqGrid('getGridParam','colModel')
out:[]
о_О

hotfix:

in grid.import.js

replace all:

gprm.colNames.splice(0);

gprm.colModel.splice(0); 

with:

gprm.colNames=gprm.colNames.slice(1);

gprm.colModel=gprm.colModel.slice(1);

22/01/2010
21:33
Avatar
mryle
Member
Members
Forum Posts: 8
Member Since:
18/08/2009
sp_UserOfflineSmall Offline

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

24/01/2010
07:20
Avatar
telubeer
Guest
Guests

Yes, this is a bug. If the goal is just remove first column from an array we need to use x=x.slice(1) method bkz x.splice(0) just truncate our arrays if we use browser different from IE.

If you dont want wait when Tony fix it in github  you can make changes yourself.

24/01/2010
17:36
Avatar
markw65
Member
Members
Forum Posts: 179
Member Since:
30/07/2009
sp_UserOfflineSmall Offline

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

24/01/2010
17:56
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information