Jquery Datatable在asp.net webforms中的分页



我有一个API,它接受页码和页面大小作为返回用户详细信息的参数。将数据加载到jquery数据表。每次需要将页码和大小传递给API以获取数据。我怎么能得到并通过页码webmethod和启用下一个按钮所有的时间。因为当我加载第一次数据时,它只显示页码为1,下一个按钮被禁用。

var tableUserDetails = $("#grdUser").DataTable({
processing: true,
filter: true,
orderMulti: false,
paging: true,
searching: true,
bFilter: true,
bsort: true,
bInfo: true,
pagingType: "simple",
columns: [{ "data": "Id" },
{ "data": "Name" },
{ "data": "userName" },
{ "data": "email" },
{ "data": "role" }
]
});
function getUsers() {
var info =tableUserDetails.page.info();
$.ajax({
data: '{pageNumber:' + info.page+1 + ', pageSize:' + 10 + '}',
type: "POST",
url: "MyPage.aspx/GetUsers",
contentType: Constants.ContentType,
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
alert("Request: " + XMLHttpRequest.toString() + "nnStatus: " + textStatus + "nnError: " + errorThrown);
},
success: function (result) {

},
});
}

我认为你正在寻找这个:数据表服务器端处理。您的配置没有加载部分数据。当您设置数据集时,它假设您拥有所有的行。

$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "../server_side/scripts/server_processing.php"
} );
} );

返回的数据格式应该是这样的:

{
"draw": 3,
"recordsTotal": 57,
"recordsFiltered": 57,
"data": [
[
"Airi",
"Satou",
"Accountant",
"Tokyo",
"28th Nov 08",
"$162,700"
],
/* etc */
一个类似c#的响应示例:
/// <summary>
///     Resultset to be JSON stringified and set back to client.
/// </summary>
[Serializable]
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class DataTableResultSet
{
/// <summary>Array of records. Each element of the array is itself an array of columns</summary>
public List<List<string>> data = new List<List<string>>();
/// <summary>value of draw parameter sent by client</summary>
public int draw;
/// <summary>filtered record count</summary>
public int recordsFiltered;
/// <summary>total record count in resultset</summary>
public int recordsTotal;
public string ToJSON()
{
return JsonConvert.SerializeObject(this);
}
}

编辑-如何使用ajax发布

$(document).ready(function () {
$('#mytable').DataTable({
processing: true,
serverSide: true,
ajax: {
data: '{pageNumber:' + info.page+1 + ', pageSize:' + 10 + '}',
type: "POST",
url: "MyPage.aspx/GetUsers",
contentType: Constants.ContentType,
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
alert("Request: " + XMLHttpRequest.toString() + "nnStatus: " + textStatus + "nnError: " + errorThrown);
},
success: function (result) {

}
});
});

最新更新