EasyUI Forum
May 06, 2024, 10:48:21 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: Pagination and sorting client side (treegrid and datagrid) [Solved]  (Read 10383 times)
lloyd
Newbie
*
Posts: 29


View Profile Email
« on: October 07, 2015, 05:26:58 AM »

I have been unable to get paging and sorting working with the built-in functions. The sort function only sorts the visible page and not all the data. I think it needs .allRows add.

My solution:

Code:
        // Custom sort need for pagination
        dg.datagrid({
            onBeforeSortColumn: function(sort, order) {
                var data = $(this).data('datagrid').allRows;
                var opts = $(this).datagrid('getColumnOption', sort);
                
                data.sort(function(a, b) {
                    // Call sort function?
                    if (typeof opts.sorter === 'function') {
                        if (order === "asc") {
                            return opts.sorter.call(this, a[sort], b[sort]);
                        }
                        return opts.sorter.call(this, b[sort], a[sort]);
                    }
                });
                
                $(this).datagrid('loadData', data);
                
                // MUST return false to cancel easyUI sort
                return false;
            }
        });

And I has to modify jquery.easyui.min.js
The datagrid-sort... class is before the call to onBeforeSortColumn
Code:
_645.find("div.datagrid-cell").removeClass("datagrid-sort-asc datagrid-sort-desc");
for(var i=0;i<_640.length;i++){
var col=_614(_63c,_640[i]);
_645.find("div."+col.cellClass).addClass("datagrid-sort-"+_641[i]);
}
if(opts.onBeforeSortColumn.call(_63c,_63f.sortName,_63f.sortOrder)==false){
return;
}


The only problem I have is I am unable to sort on treegrid children.

Please fix the sort and pagination in the EasyUI code.
« Last Edit: October 08, 2015, 03:34:15 AM by lloyd » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: October 07, 2015, 07:16:37 PM »

The 'clientPaging' method has the built-in sorting functionality. Please refer to http://www.jeasyui.com/demo/main/index.php?plugin=DataGrid&theme=default&dir=ltr&pitem=Client%20Side%20Pagination
Logged
lloyd
Newbie
*
Posts: 29


View Profile Email
« Reply #2 on: October 08, 2015, 03:27:03 AM »

Thanks stworthy, all working great Smiley
I wished this demo was in the downloads as it would have saved a lot of time.
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!