EasyUI Forum
May 01, 2024, 04:47:50 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How to get datagrid query parameters  (Read 7355 times)
jkdoyle
Newbie
*
Posts: 25


View Profile Email
« 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).
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 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
Logged
jkdoyle
Newbie
*
Posts: 25


View Profile Email
« Reply #2 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?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #3 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);
}
});
}
})
Logged
jkdoyle
Newbie
*
Posts: 25


View Profile Email
« Reply #4 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!
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #5 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)
Logged
jkdoyle
Newbie
*
Posts: 25


View Profile Email
« Reply #6 on: July 31, 2019, 07:44:42 AM »

Perfect! Thanks a ton!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!