Json data format issue
Json data format issue
I have the following data returned from sever side.
{
items: [
[ { id: "1", pNo: "ddd", customer: {id: "222", name: "test1" } }]
[ { id: "2", pNo: "ddf", customer: {id: "333", name: "test2" } }]
....
....
]
}
The data format is not matched with the one that datatable required.
As this is a migration project, I don't want to change sever side code.
Is there any api or callback to use to manipulate the data returned from server side before passing it to datatable? Any help would be appreciated. Thanks.
This question has an accepted answers - jump to answer
Answers
There are two things I see:
Assuming you are using
ajax
within the Datatables code you can useajax.dataSrc
to set the dataSrc toitems
. See the first example in the docs.You have nested objects. This example may help:
https://datatables.net/examples/ajax/objects_subarrays.html
Hope these answer your questions. If not please provide more specifics.
Kevin
Thanks kthorngren and Kevin. But when using dataSrc to return items, how can I set recordsTotal and recordsFiltered to datatable as I found it always shows me the following page info and the next button is always disabled.
Those two values reflect the current data set - so recordsTotal is the max number of records, and recordsFiltered is the number of records that match the current filtering. They should be set correctly in your returned JSON as shown in this example here.
Cheers,
Colin