The server is returning 15 records per page and the total records are over 2000. I'd like to display first 15 records and then on every click of the 'Next' button , display the remaining all records, (15 per page). For this do we do a server side pagination or client side???
Here is my table and the attributes I'm using for pagination in DataTables:
var tableData = self.accountCollection.getData();
var tableColumns = this.accountCollection.getColumns();
var totalRecs = this.accountCollection.length;
//create the UI grid containing the list of items
this.resultsTable = tableEl.dataTable( {
"bServerSide": true,
"sEcho": 3,
"iTotalRecords": totalRecs,
"iTotalDisplayRecords": 15,
"aaData": tableData,
"aoColumns": tableColumns,
"aaSorting": [[1,'asc']],
});
getData: function () {
var returnData = [];
$.each(this.models, function (idx, accountModel) {
returnData.push(accountModel.attributes);
});
return returnData;
},
The returnData
will return me an Object that has fields I will be populating I a table.
Object returned (roughly):
Object
accountName: "No Company"
address1: "1234 asdf"
address2: ""
billingAcctId: null
billingSystem: null
city: "mountain view"
comments: null
country: "USA"
The getData() function will be then called to return the data from the database using:
var tableData = this.accountCollection.getData()
So basically tableData will have the necessary fields and values to display in table. Now I may have more than 1000 records returned from the server. Hence I needed pagination.
The one in fiddle is what I tried and does not have any impact on the paginatin.
I think I have the basic pagination that comes with the DataTables, but now I need to have a server side, to get only 15 records to display at a time, and on click of 'next' and 'prev' button i should be able to make ajax calls to get the remaining records 15 per page.
I hope this helps you understand better. Please let me know if you need more details.
How can I achieve pagination using DataTables?
Thanks
Pagination works total displayed record you need to perform following minimum changes.
"iTotalDisplayRecord" will be total filtered records
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With