我才发现其实easyui分页如此简单,现在我和大家分享一下成果,不在让后人在这上面浪费时间。 这里要说一下 java 也可以用主要是传递tatol 一下示例是asp.net
首先是前台
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UserGroupManage.aspx.cs" Inherits="rightPage_sysManager_GroupManage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>用户组管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="../../js/jquery-easyui1.3.2/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="../../js/jquery-easyui1.3.2/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../js/jquery-easyui1.3.2/locale/easyui-lang-zh_CN.js"></script>
<link href="../../js/jquery-easyui1.3.2/themes/icon.css" rel="stylesheet" type="text/css" />
<link href="../../js/jquery-easyui1.3.2/themes/gray/easyui.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function(){
$('#tbuser').datagrid({
url: "../../code/UserGroupManage.ashx?iType=3&r="+Math.random(),
title: '用户组管理',
width: $("#main").width(),
height: $("#main").height(),
fitColumns: true,
nowrap:false,
pagination:true, //重点
pageSize:10,
pageList:[10,20,30],
singleSelect:true,
idField:'cGroupName',frozenColumns:[[
{field:'ck',checkbox:true},
]],
columns:[[
{field:'code',title:'编号',width:100,align:'center'},
{field:'cGroupName',title:'组名',width:100,align:'center'},
{field:'cDesc',title:'备注',width:100,align:'center'},
{field:'opt',title:'操作工作组',width:100,align:'center',
formatter:function(value,rec){
return '<span style="color:red;cursor:pointer;"><a href="#" class="easyui-linkbutton" οnclick="editRow(\''+rec.cGroupName
+'\')">修改</a> <a href="#" class="easyui-linkbutton" οnclick="deleteRow(\'' + rec.cGroupName + '\')">删除</a></span>';
}
},
]],
rowStyler:function(index,row,css){
if (row.listprice>80){
return 'background-color:#6293BB;color:#fff;font-weight:bold;';
}
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div style="margin:10px 0;"><a href="#" id="btnAddUserGroup" class="easyui-linkbutton" οnclick="openUser()">添加用户组</a></div>
<table id="tbuser" ></table>
</form>
</body>
</html>
这个页面后台什么都没有
UserGroupManage.ashx
<%@ WebHandler Language="C#" Class="UserGroupManage" %>
using System;
using System.Web;
using System.Web.SessionState;
using System.Data;
using System.Text;
public class UserGroupManage : System.Web.IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
sysStructureHelp help = new sysStructureHelp();
SendUi send = new SendUi();
context.Response.ContentType = "text/plain";
//Top pageSize
int pageSize = Convert.ToInt32(Param("rows"));
//页数
int pageIndex = Convert.ToInt32(Param("page"));
int pageCount = help.GetData("select * from dbo.t_SA_UserGroupList where iUserType=2 ").Rows.Count;
System.Data.DataTable dt = help.GetData("select top " + pageSize + " * from dbo.t_SA_UserGroupList where iUserType=2 and id not in (
select top (" + pageSize + " * (" + pageIndex + "-1)) id from t_SA_UserGroupList where iUserType=2 order by id ) order by id");
//System.Data.DataTable dt = help.GetData("select * from dbo.t_SA_UserGroupList where iUserType=2 ");
cresult = "{\"total\":" + pageCount + ",\"rows\":" + Dtb2Json(dt) + "}";//这一句是重点,只要把total(查询数据的总行数)传递到页面,分页也就算好了,其他easy给设置好了
context.Response.Write(cresult);
}
public bool IsReusable {
get {
return false;
}
}
/ <summary>
/ 将datatable转换为json
/ </summary>
/ <param name="dtb">Dt</param>
/ <returns>JSON字符串</returns>
private string Dtb2Json(System.Data.DataTable dtb)
{
//javascript序列化函数
System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
//创建集合列表
System.Collections.ArrayList dic = new System.Collections.ArrayList();
//dic.Add(drows);
//按照行来循环
foreach (DataRow dr in dtb.Rows)
{
System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
//按照列来循环
foreach (DataColumn dc in dtb.Columns)
{
drow.Add(dc.ColumnName, dr[dc.ColumnName]);
}
dic.Add(drow);
}
//序列化
string cresult = jss.Serialize(dic);
return cresult;
}
private string Param(string Params)
{
return HttpContext.Current.Request.Params[Params];
}
}
补充一下,如果你datatable转换为json 的方法不和我一样没事,只要cresult = 的格式是这样的就行
{"total":11,"rows":[{"ID":35,"cGroupName":"ww1","cDesc":"deferer","iHspPower":0,"iIdsPower":0,"iDbsPower":0,"iSvsPower":0,"iAppPower":0,"iLogPower":0,"iUserType":2,"cUserPermission":"101,101P1,101P2,101P3,","code":"8"},{"ID":37,"cGroupName":"123","cDesc":"4422","iHspPower":0,"iIdsPower":0,"iDbsPower":0,"iSvsPower":0,"iAppPower":0,"iLogPower":0,"iUserType":2,"cUserPermission":"101,101P1,101P2,","code":"10"}]}
最后一张图