EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: lloyd on October 07, 2015, 05:26:58 AM



Title: Pagination and sorting client side (treegrid and datagrid) [Solved]
Post by: lloyd 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.


Title: Re: Pagination and sorting client side (treegrid and datagrid)
Post by: stworthy 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


Title: Re: Pagination and sorting client side (treegrid and datagrid)
Post by: lloyd on October 08, 2015, 03:27:03 AM
Thanks stworthy, all working great :)
I wished this demo was in the downloads as it would have saved a lot of time.