Trying to page the JQuery DataTables control using AjaxSource pointing to a Action in my controller. I can't get the datatables paging control to display more then one page, despite the ajax call and the datatable itself working. Using DataTables 1.8.1., JQuery 1.4.1, MVC2
To demonstrate the issue ive created a list of string arrays,
var data = new List<string[]>() {
new string[] {"1", "a1", "a2", "a3"},
new string[] {"2", "b1", "b2", "b3"},
new string[] {"3", "c1", "c2", "c3"},
...
...
new string[] {"39", "c1", "c2", "c3"},
new string[] {"40", "a1", "a2", "a3"}
};
I page the list and return it from my controller
var pagedData = data.Skip(param.iDisplayStart*param.iDisplayLength)
.Take(param.iDisplayLength);
return Json(new
{
sEcho = param.sEcho,
iTotalRecords = data.Count,
iTotalDisplayRecords = pagedData.Count(),
aaData = pagedData
},
JsonRequestBehavior.AllowGet);
My DataTable is built via
$(document).ready(function ()
{
$('#myDataTable').dataTable({
"bServerSide": true,
"sAjaxSource": "../ApplicationLog/AjaxHandler",
"bProcessing": true,
"sPaginationType": "full_numbers",
"aoColumns": [
{ "sName": "COLONE" },
{ "sName": "COLTWO" },
{ "sName": "COLTHREE" },
{ "sName": "COLFOUR" }
]
});
});
This Ajax call calls the Action and publishes the first 10 rows to my table, which reports that it's 'Showing 1 to 10 of 10 entries (filtered from 40 total entries)'.
The issue I have is with the pager on the datatable, which only displays the buttons
'First', 'Previous', '1', 'Next', 'Last'
Even though I have four pages of data to show. If I click any of 'First', 'Previous', 'Next' or 'Last', my action is not called.
Am I missing something obvious? Any help would be appreciated.
Thanks in advance, Ben