If JSON result is an array with numbered keys, it says "No data available in table"

If JSON result is an array with numbered keys, it says "No data available in table"

princeofnaxosprinceofnaxos Posts: 26Questions: 9Answers: 0

Using ajax to retrieve the data for the table, I get an object with numbered keys, e.g.

{ "12" : { "amount" : "34" }, "15" : { "amount" : "36" } }

With this, no data is displayed in the table. Why?

Is there another way I can display this data?

Answers

  • allanallan Posts: 63,468Questions: 1Answers: 10,466 Site admin

    As the manual notes:

    The main data source used for a DataTable must always be an array

    You can have objects in that array as the documentation goes on to explain, but there must be an array of entries, with one entry per row.

    You'd need to convert your object to an array. That could be done with $.map or similar.

    Allan

This discussion has been closed.