62,046
社区成员
发帖
与我相关
我的任务
分享
<head id="Head1" runat="server">
<title></title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.4.1/demo/demo.css" />
<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript" language="javascript">
$(function ()
{
$('#tt').datagrid({
idField: 'LoginID',
url: 'Handler7.ashx',
loadMsg: '数据装载中......',
sortName: 'LoginID',
singleSelect: true,
columns: [[
{ field: 'UserName', title: '姓名', width: $(this).width() * 0.1 },
{ field: 'LoginID', title: '编号', width: $(this).width() * 0.1 ,sortable:true},
{ field: 'Department', title: '部门', width: $(this).width() * 0.1 },
{ field: 'Post', title: '职务', width: $(this).width() * 0.1 },
{ field: 'Sex', title: '性别', width: $(this).width() * 0.1 }
]],
pagination: true,
rownumbers: true
});
//设置分页控件
var p = $('#tt').datagrid('getPager');
$(p).pagination({
pageSize: 1000,//每页显示的记录条数,默认为10
pageList: [1000,2000,3000],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
});
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="tt" class="easyui-datagrid" data-options="singleSelect:true,collapsible:true,rownumbers:true,autoRowHeight:false,height:650,width:1000,method:'get',toolbar:'#tb',striped:true,">
</table>
</div>
</form>
</body>
</html>
<%@ WebHandler Language="C#" Class="Handler7" %>
using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using System.Text;
public class Handler7 : IHttpHandler {
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
SqlHelp sqla = new SqlHelp();
string stra = "select LoginID,UserName,Department,Sex,Post from tOAPower";
DataTable dta = sqla.GetDataTable(stra);
sqla.SqlClose();
string json = JsonConvert.SerializeObject(dta);
context.Response.Write(json);
}
public bool IsReusable
{
get
{
return false;
}
}
}
public class DataGridJsonResult
{
/// <summary>
/// 总记录行数
/// </summary>
[JsonProperty(PropertyName = "total")]
public long Total { get; set; }
/// <summary>
/// 每一行数据
/// </summary>
[JsonProperty(PropertyName = "rows")]
public IList Rows { get; set; }
}
前端的分页代码,可用如下方式实现:
jQuery('#list').datagrid({
title: 'XXXX列表',
idField: 'id',
fitColumns: true,
toolbar: '#toolbar',
height: 'auto',
pageNumber: 1,
pageSize: 5,
pageList: [5, 10, 15, 20, 30, 40],
url: '....',
queryParams: {},
pagination: true,
remoteSort: false,
columns: [[
// ...
]], onLoadSuccess: function (data) {
// ...
}
});