Reputation: 94
I have created a table
<table id="test" class="table table-striped"></table>
Now i dont want to use ServerSide processing. So i made this client script given below
$.ajax({
type: "POST",
url:"http://URL/demo",
data:{
codeType : '10'
},success:function(data1){
var dt = [];
$.each(data1,function(i,v) {
dt.push([data1[i].id,data1[i].id1,data1[i].id2,data1[i].id3,data1[i].id4,data1[i].id5]);
});
var table = $('#test').DataTable({
"data": dt,
"bProcessing": true,
"aoColumns": [
{"title":"ID", visible:false},
{"title":"ID1"},
{"title":"ID2"},
{"title":"ID3"},
{"title":"ID4"},
{"title":"ID5"}
]
});
}
});
I could get the proper data in this table. But i have 14000 records in Database but this table showing only 500 entries. Why? How can i show up all the records in the table?
Upvotes: 1
Views: 186
Reputation: 85528
A wild guess, your $.each()
loop is not finished at the time you initialise the DataTable
(?) Use a promise to ensure you are initialising only when()
the loop is completed :
$.when(
$.each(data1,function(i,v) {
dt.push([data1[i].id,data1[i].id1,data1[i].id2,data1[i].id3,data1[i].id4,data1[i].id5]);
})
).then(function() {
table = $('#test').DataTable({
"data": dt,
"bProcessing": true,
...
})
})
This will ensure that the dataTable is instantiated when and only when $.each
is completed, regardless of 1 row, 14.000 rows or never if the browser crashes :)
Upvotes: 1