easyUI 数据表格客户分页
2016-06-15 09:39
363 查看
<!DOCTYPE html>
<html>
<head>
<meta
charset="UTF-8">
<title>Client Side Pagination in DataGrid - jQuery EasyUI Demo</title>
<link
rel="stylesheet"
type="text/css"
href="../../themes/default/easyui.css">
<link
rel="stylesheet"
type="text/css"
href="../../themes/icon.css">
<link
rel="stylesheet"
type="text/css"
href="../demo.css">
<script
type="text/javascript"
src="../../jquery.min.js"></script>
<script
type="text/javascript"
src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Client Side Pagination in DataGrid</h2>
<p>This sample shows how to implement client side pagination in DataGrid.</p>
<div
style="margin:20px
0;"></div>
<table
id="dg"
title="Client Side Pagination"
style="width:700px;height:300px"
data-options="
rownumbers:true,
singleSelect:true,
autoRowHeight:false,
pagination:true,
pageSize:10">
<thead>
<tr>
<th
field="inv"
width="80">Inv
No</th>
<th
field="date"
width="100">Date</th>
<th
field="name"
width="80">Name</th>
<th
field="amount"
width="80"
align="right">Amount</th>
<th
field="price"
width="80"
align="right">Price</th>
<th
field="cost"
width="100"
align="right">Cost</th>
<th
field="note"
width="110">Note</th>
</tr>
</thead>
</table>
<script>
function getData(){
var rows
=
[];
for(var
i=1; i<=800;
i++){
var amount
=
Math.floor(Math.random()*1000);
var price
=
Math.floor(Math.random()*1000);
rows.push({
inv:
'Inv No '+i,
date: $.fn.datebox.defaults.formatter(new
Date()),
name:
'Name '+i,
amount: amount,
price: price,
cost: amount*price,
note:
'Note '+i
});
}
return rows;
}
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({
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(){
$('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData',
getData());
});
</script>
</body>
</html>
<html>
<head>
<meta
charset="UTF-8">
<title>Client Side Pagination in DataGrid - jQuery EasyUI Demo</title>
<link
rel="stylesheet"
type="text/css"
href="../../themes/default/easyui.css">
<link
rel="stylesheet"
type="text/css"
href="../../themes/icon.css">
<link
rel="stylesheet"
type="text/css"
href="../demo.css">
<script
type="text/javascript"
src="../../jquery.min.js"></script>
<script
type="text/javascript"
src="../../jquery.easyui.min.js"></script>
</head>
<body>
<h2>Client Side Pagination in DataGrid</h2>
<p>This sample shows how to implement client side pagination in DataGrid.</p>
<div
style="margin:20px
0;"></div>
<table
id="dg"
title="Client Side Pagination"
style="width:700px;height:300px"
data-options="
rownumbers:true,
singleSelect:true,
autoRowHeight:false,
pagination:true,
pageSize:10">
<thead>
<tr>
<th
field="inv"
width="80">Inv
No</th>
<th
field="date"
width="100">Date</th>
<th
field="name"
width="80">Name</th>
<th
field="amount"
width="80"
align="right">Amount</th>
<th
field="price"
width="80"
align="right">Price</th>
<th
field="cost"
width="100"
align="right">Cost</th>
<th
field="note"
width="110">Note</th>
</tr>
</thead>
</table>
<script>
function getData(){
var rows
=
[];
for(var
i=1; i<=800;
i++){
var amount
=
Math.floor(Math.random()*1000);
var price
=
Math.floor(Math.random()*1000);
rows.push({
inv:
'Inv No '+i,
date: $.fn.datebox.defaults.formatter(new
Date()),
name:
'Name '+i,
amount: amount,
price: price,
cost: amount*price,
note:
'Note '+i
});
}
return rows;
}
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({
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(){
$('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData',
getData());
});
</script>
</body>
</html>
相关文章推荐
- easyui------显示隐藏列功能
- 如何使用jquery easyui创建标签组件
- jQuery寻找n以内完全数的方法
- 推荐10个2014年最佳的jQuery视频插件
- jquery+CSS3实现淘宝移动网页菜单效果
- 采用easyui tree编写简单角色权限代码的方法
- jQuery实现本地预览上传图片功能
- jquery实现触发时更新下拉列表内容的方法
- 基于jquery中children()与find()的区别介绍
- 了解jQuery技巧来提高你的代码(个人觉得那个jquery的手册很不错)
- 轻松学习jQuery插件EasyUI EasyUI实现拖动基本操作
- 基于jQuery实现网页打印功能
- jQuery Easyui 验证两次密码输入是否相等
- easyui window refresh 刷新两次的解决方法(推荐)
- 在easyUI开发中,出现jquery.easyui.min.js函数库问题的解决办法
- 实例讲解jQuery EasyUI tree中state属性慎用
- EasyUI布局 高度自适应
- JQuery打造PHP的AJAX表单提交实例
- jquery easyui使用心得
- jQuery EasyUi实战教程之布局篇