由于项目原因,用了jquery easyui 感觉界面不错,皮肤样式少点,可是官网最近打不开了,资料比较少,给的demo没有想要的效果,今天在用datagrid 做分页显示的时候,折腾了半天,网上的资料也比较少,后自己动手,终于解决,废话不说,开始:

datagrid分页有一个附加的分页控件,只需后台获取分页控件自动提交的两个参数rows每页显示的记录数和page;//当前第几页

然后读取相应页数的记录,和总记录数total一块返回即可 界面如下:

1、下边是datagrid的显示对话框,我直接用table把列头显示出来,感觉比用js写要易于阅读

<table id="list_data" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th field="fldAppDept" width="100">部门</th>
<th field="fldAppNode" width="100">网站</th>
<th field="fldAppName" width="100">名称</th>
<th field="fldAppMgr" width="100">管理员</th>
<th field="fldAppNote" width="100">注释</th>
<th field="fldAppType" width="100">类型</th>
<th field="fldTelphone" width="100">电话</th>
<th field="fldAppImg" width="100">职务</th>
<th field="fldAppMonitor" width="100">启用监测</th>
<th field="fldAppLevel" width="100">要重级别</th>
</tr>
</thead>
</table>

2、js代码,用于构建datagrid

注意 要想显示分页控件,pagination属性必须为true

$(function() {
//datagrid初始化
$('#list_data').datagrid({
title:'应用系统列表',
iconCls:'icon-edit',//图标
width: 700,
height: 'auto',
nowrap: false,
striped: true,
border: true,
collapsible:false,//是否可折叠的
fit: true,//自动大小
url:'listApp.action',
//sortName: 'code',
//sortOrder: 'desc',
remoteSort:false,
idField:'fldId',
singleSelect:false,//是否单选
pagination:true,//分页控件
rownumbers:true,//行号
frozenColumns:[[
{field:'ck',checkbox:true}
]],
toolbar: [{
text: '添加',
iconCls: 'icon-add',
handler: function() {
openDialog("add_dialog","add");
}
}, '-', {
text: '修改',
iconCls: 'icon-edit',
handler: function() {
openDialog("add_dialog","edit");
}
}, '-',{
text: '删除',
iconCls: 'icon-remove',
handler: function(){
delAppInfo();
}
}],
});
//设置分页控件
var p = $('#list_data').datagrid('getPager');
$(p).pagination({
pageSize: 10,//每页显示的记录条数,默认为10
pageList: [5,10,15],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
/*onBeforeRefresh:function(){
$(this).pagination('loading');
alert('before refresh');
$(this).pagination('loaded');
}*/
});
});

3、后台我是通过struts2处理的数据 返回json串

private JSONObject result;//返回的json  

    private String rows;//每页显示的记录数  

    private String page;//当前第几页  

        private AppServiceInter appService;  

    public JSONObject getResult() {
return result;
}
public void setResult(JSONObject result) {
this.result = result;
}
public void setAppService(AppServiceInter appService) {
this.appService = appService;
} public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
/**
* 查询应用系统
* @return
*/
public String listApp() {
System.out.println("---------------");
//当前页
int intPage = Integer.parseInt((page == null || page == "0") ? "1":page);
//每页显示条数
int number = Integer.parseInt((rows == null || rows == "0") ? "10":rows);
//每页的开始记录 第一页为1 第二页为number +1
int start = (intPage-1)*number; List<TblApp> list = appService.findByPageApp(start,number);//每页的数据,放入list
Map<String, Object> jsonMap = new HashMap<String, Object>();//定义map
jsonMap.put("total", appService.getCountApp());//total键 存放总记录数,必须的
jsonMap.put("rows", list);//rows键 存放每页记录 list
result = JSONObject.fromObject(jsonMap);//格式化result 一定要是JSONObject //result = JSONArray.fromObject(jsonMap);
return SUCCESS;
}

4、附上struts.xml配置文件

<package name="app" extends="json-default">
<action name="listApp" class="appAction" method="listApp">
<result type="json">
<param name="root">result</param>
</result>
</action>
</package>

特写出这些,方便自己或他人以后参考 ,如果有什么问题大家可以留言......

本文转自:http://www.cnblogs.com/huozhicheng/archive/2011/09/27/2193605.html

jquery easyui datagrid 分页详解的更多相关文章

  1. jquery easyui datagrid 分页 详解

    前些天用jquery easyui的table easyui-datagrid做分页显示的时候,折腾了很久,后来终于解决了.其实不难,最主要我不是很熟悉前端的东西. table easyui-data ...

  2. jquery easyui datagrid 分页 详解(java)

    1.首先引入easyui包,可以在官方网站下载,http://www.jeasyui.com/download/index.php <link rel="stylesheet" ...

  3. easyui datagrid 分页略解

    easyui datagrid 本身自带了分页功能. 但是这个需要你自己控制. 在后台可以得到两个datagrid的参数,rows 和page.其中rows是每页要显示的个数,page是第几页.单纯的 ...

  4. jquery easyui datagrid 分页实现---善良公社项目

    接着上篇文章,接下来给大家分享分页的实现,分页其实多多少少见过很有几种,框架中带的图片都特别的好看,会给用户以好的使用效果,具体实现,需要自己来补充代码: 图示1: 通常情况下页面数据的分页显示分成真 ...

  5. jquery easyui datagrid 分页实现

    通常情况下页面数据的分页显示分成真假两种.真分页是依靠后台查询时控制调出数据的数量来实现分页,也就是说页面在后台对数据进行处理,仅传输当前需要页的数据到前台来显示.而假分页则是后台一次性将所有的数据一 ...

  6. JQuery easyui Datagrid 分页事件

    easyui是Jquery中的一个轻量级UI插件,提供了一些诸如window.datagrid.button等控件.现在主要说说Datagrid中分页控件的使用. easyui中可以单独添加分页pag ...

  7. jQuery EasyUI datagrid实现本地分页的方法

    http://www.codeweblog.com/jquery-easyui-datagrid%e5%ae%9e%e7%8e%b0%e6%9c%ac%e5%9c%b0%e5%88%86%e9%a1% ...

  8. jquery easyui datagrid使用参考

    jquery easyui datagrid使用参考   创建datagrid 在页面上添加一个div或table标签,然后用jquery获取这个标签,并初始化一个datagrid.代码如下: 页面上 ...

  9. 扩展jquery easyui datagrid编辑单元格

    扩展jquery easyui datagrid编辑单元格 1.随便聊聊 这段时间由于工作上的业务需求,对jquery easyui比较感兴趣,根据比较浅薄的js知识,对jquery easyui中的 ...

随机推荐

  1. VirtualBox共享文件夹等高级特性

    转自: http://blog.csdn.net/longerzone/article/details/32119457 http://www.oschina.net/translate/10-vir ...

  2. 【云计算】Dockerfile、镜像、容器快速入门

    Dockerfile.镜像.容器快速入门 1.1.Dockerfile书写示例 Dockerfile可以用来生成Docker镜像,它明确的定义了Image的生成过程.虽然直接修改容器也可以提交生成镜像 ...

  3. ASP.NET - 视图状态概述

    本文转载自dodream 视图状态是 ASP.NET 页框架用于在往返过程之间保留页和控件值的方法.在呈现页的 HTML 标记时,必须在回发过程中保留的页和值的当前状态将被序列化为Base64 编码字 ...

  4. 【JAVA、C++】 LeetCode 008 String to Integer (atoi)

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  5. 【JAVA、C++】LeetCode 016 3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  6. HDU2044 小蜜蜂斐波那契

    一只小蜜蜂... Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  7. linux下如何设置vip(虚拟ip)

    在做HA的时候需要为服务器设计虚拟IP,也就是一个主机对应多个IP地址?刚听起来好神奇,原来这样也是可能的看了下面的这个链接 自己配了一下http://hi.baidu.com/pbottle/ite ...

  8. Babelfish(poj 2503)

    大致题意: 输入一个字典,字典格式为“英语à外语”的一一映射关系 然后输入若干个外语单词,输出他们的 英语翻译单词,如果字典中不存在这个单词,则输出“eh” #include<iostream& ...

  9. Android之Intent深入

    Android中的意图包含多种用法,本文主要包括以下内容 显式意图 隐匿意图 要求结果回传的意图 显式意图 :必须指定要激活的组件的完整包名和类名 (应用程序之间耦合在一起) 一般激活自己应用的组件的 ...

  10. NGITOSS

    https://sourceforge.net/projects/ngnms/files/?source=navbar http://stackoverflow.com/questions/17511 ...