Data table doesn't show all results at the first moment
Data table doesn't show all results at the first moment
Hi there,
I am very new to DataTables. I'm facing an issue related to the visibility of my results. I'm making an ajax request which returns 5155 items, ordered alphabetically.
But not all of these items are being shown at the first moment. It seems DataTables makes a sumarization of the data, and, for performance issues, "chooses" only some data to show.
For example, I have a lot of words that begin with 'A', but only a few of them are being shown.
Is there anything I need to set on my options to avoid this situation?
That's how my table is being initialized:
$('#myTable').DataTable({
ajax: {
url: "/my_service",
dataSrc: function(myList){
var data = [];
for(var i = 0; myList && i < myList.length; i++){
// do some stuff here....
data.push({
field1: myList[i].field1,
field2: myList[i].field2,
field3: myList[i].field3,
field4: myList[i].field4
})
}
}
return data;
}
},
columns: [
{ data: 'field1' },
{ data: 'field2' },
{ data: 'field3' },
{ data: 'field4' }
],
scrollY: true,
deferRender: false,
scroller: true,
language: {
decimal: ',',
thousands: '.'
}
});
$('#myTable').on( 'init.dt', function (e, settings, results) {
// do some stuffs here...
} );
Is there anything I'm missing?
Thanks,
Guilherme
Answers
Hard to say without seeing an example of your data. Can you post an example (first 10 rows) of the
data
you are returning in theajax.dataSrc
function?You might not need to use the for loop depending on what your orignal data looks like. Maybe you can post a small example of
myList
.By default Datatables will sort column 0 ascending. Is the data your are asking about in column 0?
Does the information element show 5155 entries?
Kevin
Hi,
No, the field I'm talking about is on column 1. Maybe that's the point. And yes, I have 5155 entries on my array data. I've already debugged it on my browser console.
I've set the order option (https://datatables.net/reference/option/order) and now I'm almost there (THANKS!).
The problem now is the words which begins with accents ('Águas Lindas', 'Óleo', ....). DataTable is ordering them in the last positions. How can I fix it?
Thank you again!
Guilherme
Hi @guilhermemaranhao ,
I think you need to use the diacritics-sort plugin to get the ordering that you want - that will ensure the ordering is natural rather than ASCII.
Cheers,
Colin
Great, @colin! It worked!
thank you very much!