EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: devnull on March 13, 2013, 05:52:13 AM



Title: Feature Request - Auto Page Size
Post by: devnull on March 13, 2013, 05:52:13 AM
I have a feature, enhancement request: would it be possible to add an autoPageSize property /method, where the table would automatically set it's page size based on the available height ??

I have been attempting to implement my own, but are having trouble setting the page size:

http://jsfiddle.net/Chqxu/9/

Code:
    function dgResize(data){
        var psize = 2;
        $(this).datagrid('options').pageSize = psize;
        var panel = $(this).datagrid('getPanel').panel();
        var pager = $(this).datagrid('getPager').pagination();
        pager.pageList = [2,5,10,25];
        pager.pageSize = psize;   
        pager.refresh;
        pager.select;
        panel.refresh;
        $(this).datagrid('reload');
        console.log(pager.pageSize);
    }


Title: Re: Feature Request - Auto Page Size
Post by: devnull on March 19, 2013, 04:47:46 AM
Bump...

This would be a nice feature, having the table set it's optimum page size based on the available space would remove the necessity for the user to manually select the page size to fit their browser.

Thanks for considering it.



Title: Re: Feature Request - Auto Page Size
Post by: stworthy on March 19, 2013, 09:30:43 AM
The 'autoPageSize' method can be extended as:
Code:
$.extend($.fn.datagrid.methods,{
autoPageSize:function(jq){
return jq.each(function(){
var that = $(this);
that.datagrid('options').onResize = function(){
setPageSize();
};
setPageSize();

function setPageSize(){
var body2 = that.datagrid('getPanel').find('div.datagrid-view2 div.datagrid-body');
var pageSize = parseInt(body2.height()/25);
if (pageSize){
var opts = that.datagrid('options');
opts.pageSize = pageSize;
opts.pageList = [10,20,30,pageSize].sort(function(a,b){return a-b});
that.datagrid('getPager').pagination({
pageSize: opts.pageSize,
pageList: opts.pageList
}).pagination('select',opts.pageNumber);
}
}
});
}
});

To enable this feature, call 'autoPageSize' method on datagrid.
Code:
$('#dg').datagrid('autoPageSize');