easyui datagrid 前台分页

核心方法

//分页data
function pagerFilter(data, pagegrid) {
    if (typeof data.length == 'number' && typeof data.splice == 'function') {	// is array
        data = {
            total: data.length,
            rows: data
        }
    }
    var dg = pagegrid || $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
        onSelectPage: function (pageNum, pageSize) {
            opts.pageNumber = pageNum;
            opts.pageSize = pageSize;
            pager.pagination('refresh', {
                pageNumber: pageNum,
                pageSize: pageSize
            });
            dg.datagrid('loadData', data);
        }
    });
    if (!data.originalRows) {
        data.originalRows = (data.rows);
    }
    var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
    var end = start + parseInt(opts.pageSize);
    data.rows = (data.originalRows.slice(start, end));
    return data;
}

调用方式

       $(function(){
            var $dg = $('#dg');
            $dg.datagrid({
                data: pagerFilter({ "total":1, "rows": [{"id":2}]},$dg),
                loadFilter: pagerFilter,
                pageSize: 10,
                pageList: [10, 20, 50],
                rownumbers: true,
                idField: 'project_name',
                resizable: true,
                singleSelect: true,
                pagination: true,
                collapsed: false,
                collapsible: true,
                fitColumns: false,
                nowrap: false
            });
        });

  

posted @ 2016-03-11 10:18  bkyshj  阅读(1638)  评论(0编辑  收藏  举报