[英]JQuery Datatables Server Side Processing Bug
I am using the latest Nuget Datatables Package. 我正在使用最新的Nuget数据表包。
From the Nuget Package I am using the following two scripts 从Nuget包中,我正在使用以下两个脚本
<link rel="stylesheet" href="/Content/DataTables/css/jquery.dataTables.min.css" type="text/css" />
<script src="/Scripts/DataTables/jquery.dataTables.min.js"></script>
The following is my client table, it contains 28 records in the database and I am trying to display 10 records 以下是我的客户表,它包含数据库中的28条记录,而我试图显示10条记录
Below is my cshtml 下面是我的cshtml
<script>
$(document).ready(function () {
$('#clientTable').DataTable({
"order": [[1, "asc"]],
"serverSide": true,
"processing": true,
"paging": true,
"bLengthChange": false,
"iDisplayLength": "10",
"ajax": {
"url": "/Client/GetAll",
"type": "POST",
"dataType": "json"
},
"columns":
[
{
data: "ID", title: "", render: function (o) {
var template = "<div class=\"btn-group\"><button type=\"button\" class=\"btn btn-primary dropdown-toggle\" data-toggle=\"dropdown\"> Options <span class=\"caret\"></span></button>"
+ "<ul class=\"dropdown-menu\" role=\"menu\">"
+ "<li style=\"display: @InspectionMethods.ValidateDisplayAccessRights(AccessRights.ViewInspections)\">"
+ "<a href=\"/Client/View/" + o + "\">Edit</a>"
+ "</li>"
+ "<li class=\"divider\"></li>"
+ "<li style=\"display: @InspectionMethods.ValidateDisplayAccessRights(AccessRights.ManageEmployees)\">"
+ " <a href=\"/Client/Inspections/" + o + "\">View Inspections</a> "
+ "</li></ul></div>";
return template;
}
},
{ data: "Name", title: "Company" },
{ data: "CellNumber", title: "Contact Number" }
]
});
});
</script>
<div class="row">
<div class="col-md-12">
<div class="portlet">
<div class="portlet-header">
<h3 class="pull-right">
<a style="display: @InspectionMethods.ValidateDisplayAccessRights(AccessRights.ManageEmployees)" href="@Url.Action("CreateClient")" class="btn btn-success pull-right">New Client</a>
</h3>
</div> <!-- /.portlet-header -->
<div class="portlet-content">
<table id="clientTable" class="table table-striped table-bordered table-hover table-highlight"></table>
</div> <!-- /.portlet-content -->
</div> <!-- /.portlet -->
</div> <!-- /.col -->
</div> <!-- /.row -->
Here is my server side 这是我的服务器端
[HttpPost]
public ActionResult GetAll(JQDTParams model)
{
using (var context = new DatabaseContext())
{
var clients = context.Clients.Where(model).ToList();
var result = new
{
model.sEcho,
model.draw,
recordsFiltered = context.Clients.Count(model), // 28
recordsTotal = context.Clients.Count(), // 28
data = clients // 10 Items in the list
};
return Json(result, JsonRequestBehavior.AllowGet);
}
}
The result I am getting looks like this 我得到的结果看起来像这样
EDIT 1:) Pages now display. 编辑1 :)现在显示页面。
Pressing on Page 1, 2, or 3 it works and displays the correct data. 按第1、2或3页可以工作并显示正确的数据。
Now if I go to Page one and Press "Next" I get the result above where the text then says Showing 0,101 to 28 of 28 entries and if I press "Next" again to go to page three it doesn't do anything 现在,如果我转到第一页并按“下一步”,我将得到上面的结果,在文本上方显示“显示0,101至28,共28个条目” ,如果我再次按“下一步”以转到第三页,则它什么也没有
Found the problem 发现问题
It seems that jquery.Datatables handled the "iDisplayLength"
as a string instead of an int, simple change 看来jquery.Datatables将
"iDisplayLength"
作为字符串而不是int进行了简单的更改
$(document).ready(function () {
$('#clientTable').DataTable({
"order": [[1, "asc"]],
"serverSide": true,
"processing": true,
"paging": true,
"bLengthChange": false,
"iDisplayLength": 10, //Here was the problem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.