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?
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 jqGridpostData
parameter of the jqGridprmNames
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:
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With