How to populate dataTable with multidimensional array with dynamic key

How to populate dataTable with multidimensional array with dynamic key

vishnavishna Posts: 1Questions: 1Answers: 0

Hello,

I have an array like this:
"orders": {
"b0d0-e811-566": {
"order_date": "11.10.2018",
"order_amount": 10,
"customer_id": "cus1",
}
"940d-e811-940": {
"order_date": "15.10.2018",
"order_amount": 15,
"customer_id": "cus1,
}
}
b0d0-e811-566 and 940d-e811-940 are IDs and they are generated dynamically, depending on selected customer.

I want to display the following columns: order_id, order_date, order_amount, customer_id

Is there a way to populate the table when a column name is dynamic ?

Thanks!

Answers

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

    You'd need to convert the object to an array (e.g. with Array.prototype.map or $.map()). DataTables can't use an object as the source for rows (although each row can use an object as its own data source).

    Allan

This discussion has been closed.