Get current url including parameters of Jqgrid

24,622

Solution 1

jqGrid don't save somewhere the full URL appended with all parameters. So it is not possible within the jqGrid API archive this.

To see full URL you can use Firebug, Fiddler or other close tool.

In general it is well known how the url will constructed. How I understand indirectly you want use HTTP GET (mtype: "GET"). I explain the construction of the URL in case of HTTP GET.

The full URL of the GET requests will constructed from:

  • url parameter of the jqGrid
  • postData parameter of the jqGrid
  • some additional paremeters which depend on the action used (first grid load, data searching, paring and so on). The names of this additional parameters can be changed by prmNames parameter of jqGrid (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options#how_to_overwrite_global_options). For example if you define prmNames: {sort: "searchIndex", order: "searchDirection", search: null, nd: null} then parameters sidx and sord will be renamed to searchIndex and searchDirection. Parameters _search and nd will not send.

Below you find some typical urls:

  1. baseurl?_search=false&nd=1250348761396&rows=20&page=1&sidx=&sord=asc
  2. baseurl?_search=false&nd=1250348761396&rows=20&page=1&sidx=Name&sord=asc
  3. baseurl?_search=true&rows=10&page=1&sidx=Name&sord=asc&searchField=Manufacture &searchString=Micro&searchOper=bw

The first url requests loading of the first page of data, 20 rows per page, no sorting. The second url has sorting by Name. The third url contain data filtering (with simple searching) based on the filter "Manufacture begins with Micro" and sorting by Name. Results are paged by 10 rows per page and the first page are requested.

In case of using Advanced Searching or Toolbar Searching instead of Simple Searching the url will looks like a little other. Everithing are documented unter http://www.trirand.com/jqgridwiki/doku.php?id=wiki:jqgriddocs. If you do have additional questions I'll can explain all more detailed.

It is important to understand that parameters used in URL should be encoded. So if you want cunstruct url yourself like

"baseUrl?firstName=" + myFirstName + '&lastName=' + myLastName

you should don't forget to use encodeURIComponent function to encode myFirstName and myLastName. Instead of that you can use jQuery.param (see why my search code does not work on internet explorer) or better use postData parameter of the jqGrid (see jqgrid not updating data on reload and How to filter the jqGrid data NOT using the built in search/filter box. In the last case symbols '?' and '&' will be inserted in the url if it is needed and all data values will be encoded with respect of encodeURIComponent.

Solution 2

I had a similar need and solved it with this:

var myUrl = jQuery("#grid").jqGrid('getGridParam', 'url');
myUrl += "?myextraparam=something";
var postData = jQuery("#grid").jqGrid('getGridParam', 'postData');
$.each(postData, function(key, value) {
  myUrl += "&"+key+"="+encodeURIComponent(value);
});
//alert(myUrl);

For me, the above got all I needed including items from the search toolbar if used. The ?myextraparam=something should be replaced with any extra parameters you want to pass.

Share:
24,622
Luke Lowrey
Author by

Luke Lowrey

Development team manager (and developer!) specialising in web applications. Founder of austechjobs.com.au a job board for high quality Australian tech jobs.

Updated on December 15, 2020

Comments

  • Luke Lowrey
    Luke Lowrey over 3 years

    I am looking to get the full url of the last request to my ajax service made by JqGridincluding page, records per page, search params etc.

    Is there any method or collection of methods within the JqGrid api I can use to achieve this?