Overriding record count for custom server side pagination
Overriding record count for custom server side pagination
Hello,
I would like to override the record count and number of pages based on result set size using my own custom server side pagination driven by knockout. This would also include using my own paging events to reload the correct data into the KO ViewModel. I believe that providing my own paging events is straight forward to update the data that is actually displayed, but it has not been easy to figure out how to override "Showing 1 to 10 of 150 entries" when I know that there is actually 2000 in the result set that DataTables is unaware of.
I see in some extensions where people use code like:
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
{
return {
"iStart": oSettings._iDisplayStart,
"iEnd": oSettings.fnDisplayEnd(),
"iLength": oSettings._iDisplayLength,
"iTotal": oSettings.fnRecordsTotal(),
"iFilteredTotal": oSettings.fnRecordsDisplay(),
"iPage": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
"iTotalPages": oSettings._iDisplayLength === -1 ?
0 : Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
};
};
But setting my own custom values there doesn't seem to have an effect. What is the proper (preferably DT 1.10) way to achieve this?
Thanks.
Answers
I see now:
But since I'm not using "true" ssp, fnRecordsTotal isn't returning the attribute I'm updating. Maybe I should override fnRecordsTotal and friends?
I would suggest you use the
xhr
event to modify the data returned by the server to suit your needs rather than modifying DataTables core.There isn't really any way to override it (other than
xhr
). Can you not just have your model return the correct number of rows in the table? If you can't do that there, you'd still just need to get the correct number of records when you modify the JSON data.Allan
I would suggest you use the
xhr
event to modify the data returned by the server to suit your needs rather than modifying DataTables core.There isn't really any way to override it (other than
xhr
). Can you not just have your model return the correct number of rows in the table? If you can't do that there, you'd still just need to get the correct number of records when you modify the JSON data.Allan
But I am actually using knockoutjs foreach to build the table data from a knockout ViewModel which is populated from JSON, so DataTables ssp isn't used anywhere.
Are you suggesting I "fake" true DT ssp by providing my own xhr event that returns the result values expected by Datatables and also updates the knockout viewmodel?
I think I'm getting it - ish... Does your foreach populate all of the rows into the table? If so, it should just work and I would need a test case to be able to understand why it isn't.
If it doesn't and it only populates for each page and you have the
serverSide
parameter enabled, then yes, you would need to implement server-side processing (edit typo).Allan