不错呦!smile@林凯西,确保“准备文件”中的几个文件都有安装,S...您好,看了您这篇帖子觉得很有帮助。但是有个问题想请...我的修改过了怎么还被恶意注册呢 @jjjjiiii 用PJ快9年了,主要是A...PJ3啊,貌似很少有人用PJ了,现在不是WP就是z...@332347365,我当时接入时错误码没有-10...楼主,ChkValue值应为-103是什么意思呢?...大哥 你最近能看到我发的信息,请跟我联系,我有个制...
jQuery插件:DataTables分页取数据示例
编辑:dnawo 日期:2012-10-22
DataTables分页取数据示例
Default.aspx:
data.ashx:
参考资料
[1].Server-side processing:http://www.datatables.net/usage/server-side
Default.aspx:
复制内容到剪贴板
程序代码

<%@ Page Language="C#" %>
<!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>DataTables分页取数据示例 - Mzwu.COM</title>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#example").dataTable({
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bAutoWidth": false,
"bStateSave": true,
"iDisplayLength": 10,
//"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "data.ashx",
"sServerMethod": "POST",
"fnServerParams": function (aoData) {
aoData.push({"name": "name1", "value": "value1"});
aoData.push({"name": "name2", "value": "value2"});
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table id="example" width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td>Id</td>
<td>Name</td>
</tr>
</thead>
</table>
</form>
</body>
</html>
<!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>DataTables分页取数据示例 - Mzwu.COM</title>
<link rel="stylesheet" type="text/css" href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#example").dataTable({
"bLengthChange": false,
"bFilter": false,
"bSort": false,
"bAutoWidth": false,
"bStateSave": true,
"iDisplayLength": 10,
//"sPaginationType": "full_numbers",
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "data.ashx",
"sServerMethod": "POST",
"fnServerParams": function (aoData) {
aoData.push({"name": "name1", "value": "value1"});
aoData.push({"name": "name2", "value": "value2"});
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<table id="example" width="100%" border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td>Id</td>
<td>Name</td>
</tr>
</thead>
</table>
</form>
</body>
</html>
data.ashx:
复制内容到剪贴板
程序代码

<%@ WebHandler Language="C#" Class="data" %>
using System;
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System.Web.Script.Serialization;
public class data : IHttpHandler {
public void ProcessRequest (HttpContext context) {
//data
List<List<string>> data = new List<List<string>>();
for (int i = 0; i < 100; i++)
{
data.Add(new List<string> { i.ToString(), "user" + i.ToString() });
}
//Request.Form
//sEcho=1&iColumns=2&sColumns=&iDisplayStart=10&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&name1=value1&name2=value2
string sEcho = context.Request.Form["sEcho"];
int iDisplayStart, iDisplayLength;
int.TryParse(context.Request.Form["iDisplayStart"], out iDisplayStart);
int.TryParse(context.Request.Form["iDisplayLength"], out iDisplayLength);
//Server Data
ServerData serverdata = new ServerData();
serverdata.sEcho = sEcho;
serverdata.iTotalRecords = data.Count;
serverdata.iTotalDisplayRecords = data.Count;
serverdata.aaData = data.Skip(iDisplayStart).Take(iDisplayLength).ToList();
//output json
JavascriptSerializer serializer = new JavascriptSerializer();
context.Response.Write(serializer.Serialize(serverdata));
}
public bool IsReusable {
get {
return false;
}
}
}
public class ServerData
{
public string sEcho { get; set; }
public int iTotalRecords { get; set; }
public int iTotalDisplayRecords { get; set; }
public List<List<string>> aaData { get; set; }
}
using System;
using System.Web;
using System.Linq;
using System.Collections.Generic;
using System.Web.Script.Serialization;
public class data : IHttpHandler {
public void ProcessRequest (HttpContext context) {
//data
List<List<string>> data = new List<List<string>>();
for (int i = 0; i < 100; i++)
{
data.Add(new List<string> { i.ToString(), "user" + i.ToString() });
}
//Request.Form
//sEcho=1&iColumns=2&sColumns=&iDisplayStart=10&iDisplayLength=10&mDataProp_0=0&mDataProp_1=1&name1=value1&name2=value2
string sEcho = context.Request.Form["sEcho"];
int iDisplayStart, iDisplayLength;
int.TryParse(context.Request.Form["iDisplayStart"], out iDisplayStart);
int.TryParse(context.Request.Form["iDisplayLength"], out iDisplayLength);
//Server Data
ServerData serverdata = new ServerData();
serverdata.sEcho = sEcho;
serverdata.iTotalRecords = data.Count;
serverdata.iTotalDisplayRecords = data.Count;
serverdata.aaData = data.Skip(iDisplayStart).Take(iDisplayLength).ToList();
//output json
JavascriptSerializer serializer = new JavascriptSerializer();
context.Response.Write(serializer.Serialize(serverdata));
}
public bool IsReusable {
get {
return false;
}
}
}
public class ServerData
{
public string sEcho { get; set; }
public int iTotalRecords { get; set; }
public int iTotalDisplayRecords { get; set; }
public List<List<string>> aaData { get; set; }
}
参考资料
[1].Server-side processing:http://www.datatables.net/usage/server-side






评论: 0 | 引用: 0 | 查看次数: 9787
发表评论
请登录后再发表评论!