easyui分頁控件的應用
1.首先應用easyui的js和css文件
<link rel="stylesheet" type="text/css" href="../../util/jquery-easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="../../util/jquery-easyui/themes/icon.css" />
<script type="text/javascript" src="../../util/jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../util/easyui-lang-zh_CN.js"></script>//註意放在引用的最後;漢化
2.定義分頁處理方法(公共方法)
function _pagerFilter(data){
if (typeof data.length == ‘number‘ && typeof data.splice == ‘function‘){ // is array
data = {
total: data.length,
rows: data
}
}
var dg = $(this);
var opts = dg.datagrid(‘options‘);
var pager = dg.datagrid(‘getPager‘);
pager.pagination({
showPageList:false,
displayMsg:‘每頁顯示10條 共{total}條記錄‘,
onSelectPage:function(pageNum, pageSize){
opts.pageNumber = pageNum;
opts.pageSize = pageSize;
pager.pagination(‘refresh‘,{
pageNumber:pageNum,
pageSize:pageSize
});
dg.datagrid(‘loadData‘,data);
$(‘div.datagrid-header-check input[type=checkbox]‘).attr("checked",false);
}
});
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;
}
3.表格設置使用分頁
$(‘#dg‘).datagrid({
width: ‘100%‘,
height: h,
rownumbers: true,
singleSelect: true,
fit:true,
fitColumns:true,
pagination: true,//使用分頁
//......
4.加載數據時需要同時加載分頁方法
$(‘#dg‘).datagrid({loadFilter:_pagerFilter}).datagrid(‘loadData‘, {
total: data.length,
rows: data
});
easyui分頁控件的應用