Json data format issue

Json data format issue

larryularryu Posts: 2Questions: 1Answers: 0

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

  • kthorngrenkthorngren Posts: 21,300Questions: 26Answers: 4,945
    Answer ✓

    There are two things I see:

    1. Assuming you are using ajax within the Datatables code you can use ajax.dataSrc to set the dataSrc to items. See the first example in the docs.

    2. 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

  • larryularryu Posts: 2Questions: 1Answers: 0
    edited June 2018

    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.

        Showing 0 to 0 of 0 entries (filtered from NaN total entries)
    
  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

This discussion has been closed.