EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jkdoyle on July 26, 2019, 08:40:34 AM



Title: How to get datagrid query parameters
Post by: jkdoyle on July 26, 2019, 08:40:34 AM
I'm trying to access all the parameters being sent to the server for a datagrid (including the filter plugin parameters and search parameters). How do I do this? What I want to  do is send all the current query parameters to another processing page that allows users to create excel, comma-separated, or pdf files that match the current datagrid (not just the curent page, but all data).


Title: Re: How to get datagrid query parameters
Post by: jarry on July 28, 2019, 06:13:59 PM
Please refer to this example https://www.jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=material-teal&dir=ltr&pitem=Remote%20Filtering%20on%20DataGrid&sort=asc


Title: Re: How to get datagrid query parameters
Post by: jkdoyle on July 29, 2019, 07:05:32 AM
Yeah, I know how to do the processing on the server side. What I'm wondering is how I can get via jquery or javascript the current query data that has been used to create the currently viewable contents of the datagrid (including filters or searches).  How do I get the query data that was sent from a particular datagrid object with jquery?


Title: Re: How to get datagrid query parameters
Post by: jarry on July 29, 2019, 06:37:28 PM
The 'loader' function contains all the request parameters sent to server. Please override it to get these parameters.
Code:
$('#dg').datagrid({
loader: function(param, success, error){
console.log(param)
var opts = $(this).datagrid('options');
if (!opts.url) return false;
$.ajax({
type: opts.method,
url: opts.url,
data: param,
dataType: 'json',
success: function(data){
success(data);
},
error: function(){
error.apply(this, arguments);
}
});
}
})


Title: Re: How to get datagrid query parameters
Post by: jkdoyle on July 30, 2019, 07:13:32 AM
Thanks for that! Very helpful! And I can certainly use this if it is the only option.

Is there no other way to get that value? Is it not accessible in the object, say if I wanted to call the queryParams from a script on the click of a button (without loading/reloading the datagrid)?

Thanks!


Title: Re: How to get datagrid query parameters
Post by: jarry on July 30, 2019, 07:08:22 PM
This is a simpler way to store the parameters in the 'options' object.
Code:
$('#dg').datagrid({
onBeforeLoad: function(params){
var opts = $(this).datagrid('options');
opts.allParams = params;
}
})

At any time you can get it like this:
Code:
var opts = $(...).datagrid('options');
var params = opts.allParams;
console.log(params)


Title: Re: How to get datagrid query parameters
Post by: jkdoyle on July 31, 2019, 07:44:42 AM
Perfect! Thanks a ton!