EasyUI Forum
May 03, 2024, 10:01:12 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: datagrid 'sort' method without 'load'  (Read 8869 times)
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« on: March 19, 2015, 06:59:07 AM »

Hi,

I have been looking at the 'sort' method of the datagrid.
For performance, I re-use some datagrids in my application. I have to 'reset' them before re-use, and loading new data. To do this I first remove filters as I am using this extension. The method 'removeFilterRule' does this, and will not reload the data.
I also need to reset any user sort actions. My problem is that I have 'remoteFilter=true'. When I call the sort method, the datagrid is loaded after the new sort is applied.

What I really need is a 'resetSort' method, or a 'sortNoLoad' method. I understand I could copy the whole method and extend the object defaults, and then omit the 'load' part of the code, but am I missing an easier way to the same functionality?

Thanks
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 19, 2015, 07:38:06 PM »

To prevent from loading data from remote server, just return false in 'onBeforeLoad' event. If you only want to reset the sorting flag on the column header, the 'resetSort' method can be extended as below:
Code:
$.extend($.fn.datagrid.methods, {
resetSort: function(jq, param){
return jq.each(function(){
var state = $.data(this, 'datagrid');
var opts = state.options;
var dc = state.dc;
var header = dc.header1.add(dc.header2);
header.find('div.datagrid-cell').removeClass('datagrid-sort-asc datagrid-sort-desc');
param = param || {};
opts.sortName = param.sortName;
opts.sortOrder = param.sortOrder || 'asc';
if (opts.sortName){
var names = opts.sortName.split(',');
var orders = opts.sortOrder.split(',');
for(var i=0; i<names.length; i++){
var col = $(this).datagrid('getColumnOption', names[i]);
header.find('div.'+col.cellClass).addClass('datagrid-sort-'+orders[i]);
}
}
})
}
})

Usage example:
Code:
$('#dg').datagrid('resetSort');  // clear all the sorting flag
$('#dg').datagrid('resetSort', {sortName:'itemid',sortOrder:'desc'});  // reset the 'itemid' column with 'desc'
Logged
phunksta
Jr. Member
**
Posts: 54


View Profile Email
« Reply #2 on: March 26, 2015, 07:52:18 AM »

Great Thanks!
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!