0
我正在嘗試使用Datatables.net實現分頁。您能否請我解釋一下下一頁按鈕的工作原理。 ATM我得到的第一頁,但顯示不能轉到下一個,服務器端我的控制器將只取得網頁的記錄(跳過&採取...)Jquery Datatables傳呼,如何進入下一頁
我的數據表:
$('#calculation-table').DataTable(
{ // set server side processing to true
bServerSide: true,
// set controller responsible for sorting and paging
sAjaxSource: "CalculationTest/AjaxHandler",
// show processing is happening while getting data
bProcessing: true,
iDisplayLength: 15,
lengthMenu: [[15, 25, 50, -1], [15, 25, 50, "All"]],
columns: [
{ data: "BeneficialOwner" },
{ data: "Account" },
{ data: "Country" },
{ data: "Currency" },
{ data: "Year" },
{ data: "Updater" }
],
"language": {
"search": "",
"searchPlaceholder": "Search..."
}
});
});
我的控制器:
public ActionResult AjaxHandler(JQueryDataTableParamModel param, DataTableAjaxPostModel model)
{
IEnumerable<CalculationDownloadItem> calResList;
int filteredRecords;
int totalRecords;
using (var serviceFactory = new ServiceFactory())
{
var poolApi = serviceFactory.GetApiServiceCached<IPoolApi>();
var mainApi = serviceFactory.GetApiServiceCached<IMainApi>();
List<CalculationResult> calculationResultsList = mainApi.GetCalculationResults(BankId, param.iDisplayLength, param.iDisplayStart, out totalRecords, out filteredRecords);
calResList = ParseDownloadItems(calculationResultsList, poolApi, mainApi);
//count = mainApi.CountCalculationResults(BankId);
}
var calculationDownloadItems = calResList as CalculationDownloadItem[] ?? calResList.ToArray();
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = totalRecords,
iTotalDisplayRecords = filteredRecords,
aaData = calculationDownloadItems
},
JsonRequestBehavior.AllowGet);
}
問題是您沒有使用在數據表請求中發送的分頁參數。 「JQueryDataTableParamModel」對象應該有另外兩個屬性:'iDisplayLength'和'iDisplayStart',您需要在查詢中使用它來處理分頁。 [這裏是一個例子](https://stackoverflow.com/questions/25260672/how-to-pass-value-from-controller-to-jquery-datatable)這可能有幫助(如果你使用的是LINQ) – markpsmith