2

I am using cookies to load a users previous sorting and paging options. I would like to take those saved values, and set them as the parameters the server receives.

The paramaters I wish to change are as follows, (rows are replaced by max via prmNames)

/&max=20&page=1&sidx=&sord=asc

I have tried using:

   $.extend($.jgrid.defaults, {
    sidx:"fName",
    sord:"desc",
    page:2,
    rows:10});

and variations of:

      beforeRequest:function(){
        $('#grid').jqGrid('setGridParam', {
            sidx: "fName",
            sord: "desc",
            page: 2,
            max: 10
        });

    }

It changes the value for page using $.extend($.jgrid.defaults... , but I cannot get the other parameters to change.

Jaym
  • 301
  • 5
  • 14

1 Answers1

5

You need just use setGridParam to set parameters of jqGrid which have another names as sidx, sord, page and rows.

sidx -> sortname
sord -> sortorder
page -> page
rows -> rowNum

So the best would be to create jqGrid directly with the above parameters initialized from the cookie.

If you would have problem with creation the grid directly with the parameters which you need you can first create the grid with datatype: 'local' which will prevent the loading the grid. Then you change the parameters which you need and additionally set datatype to the value which you need ('json' or 'xml'). At the end you reload the grid. So the code should be like the following

$('#list').jqGrid('setGridParam', {
    datatype: 'json',
    sortname: "fName",
    sortorder: "desc",
    page: 2,
    rowNum: 10
}).trigger('reloadGrid');

If you would have problem with creation the grid directly with the parameters which you need. additionally create the grid with datatype: 'local' it will prevent the loading the grid

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Can I set the postData using the postData Object from a previous session? I can also do something like: ` beforeProcessing:function () { grid.jqGrid('setGridParam', { postData:postData }) }` – Jaym Feb 01 '12 at 21:18
  • @Jaym: In general you can, but it's depend from context whether it's correct way or not. I would recommend you to read [the answer](http://stackoverflow.com/a/8436273/315935) which describe how I understand and implement the problem. You can examine the demos which I posted. I hope it will answer on all your questions. – Oleg Feb 01 '12 at 21:24
  • I was using a technique similar to the question regarding cookies. And as you stated I was having problems since I was reaching the max cookie size. I will try implementing it locally; it looks like the best option. The demo does exactly what I was trying to accomplish. Thank you for all your help! – Jaym Feb 01 '12 at 21:55
  • very annoying that the param name doesn't match the value sent in the form values. thank you for `sidx -> sortname` saved me tons of time. I thought I was losing my mind. – timbrown Oct 18 '14 at 05:44
  • 1
    @timbrown: You are welcome! By the way you can use `prmNames` [option](http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options) of jqGrid to **rename** almost any parameter which will be sent to the server. For example `prmNames: {page:"requestedPage", rows: "rowsPerPage", sort: "sortIndex", order: "sortOrder", search: "isSearching"}`. – Oleg Oct 18 '14 at 10:08
  • @Oleg Can I see all the parameters sent to server side ? – Shamseer K Aug 22 '17 at 12:02
  • @ShamseerKSmr: Do you mean "the parameters sent to server side" or "the parameters which could be sent to server side"? To see parameters which currently sent you can use Developer Tools of Chrome/IE (press F12 to start developer tools, choose Network tab end examine the traffic) or other goo free tools like [Fiddler](http://www.telerik.com/fiddler). You will see full HTTP traffic inclusive the parameters sent to the server and the responses returned from the server. – Oleg Aug 22 '17 at 12:23
  • @Oleg thank you I am working on jqGrid VideoTutorial in asp.net mvc - first video - https://www.youtube.com/watch?v=Hpt4Ew4ySZk – Shamseer K Aug 22 '17 at 12:36
  • @ShamseerKSmr: It looks interesting, but you use **commercial** [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) but I develop **alternative** fork [free jqGrid](https://github.com/free-jqgrid/jqGrid) which I provided under MIT and GPL licenses completely free of charge. In general the video is interesting, but I would include even in the first video the information about rowids (see [here](https://free-jqgrid.github.io/getting-started/index.html#grid-internal-div)). I'd recommend to add `prmNames: { id: "EmployeeID" }` to use correct rowids. It will be important later for editing. – Oleg Aug 22 '17 at 12:53
  • @ShamseerKSmr: Additionally, there are some common ASP.NET base settings, which I recommend always to use. You use old version of Visual Studio and I'm not sure which version of ASP.NET and JSON serializer you use. I recommend to use camel conversion of JSON serializer, which are available for all JSON serializer (see [here](https://stackoverflow.com/q/17244774/315935)). It's recommended to use `Newtonsoft.Json` even with old ASP.NET MVC (by loading NuGet package) and to initialize it during application startup. It allows to use native JavaScript names (`employeeID` instead of `EmployeeID`) – Oleg Aug 22 '17 at 13:15
  • @Oleg thanks for the information, I will use free jqGrid for upcoming tutorials. can I use same code for both of these free and commercial jqGrid ? – Shamseer K Aug 23 '17 at 07:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152602/discussion-between-shamseer-k-smr-and-oleg). – Shamseer K Aug 23 '17 at 07:30