Columns.data format for this particular scenario

Columns.data format for this particular scenario

mirfilipmirfilip Posts: 2Questions: 1Answers: 0
edited June 2014 in Free community support

Hi,
I am trying to consume such an API response:

{
   "data": 
     {
      "a":
        {"b": 1},
      "c":
        {"d": 2}
     }
}

I would like to display it as :

| Some Name | Other Name | Count |
-----------------------------------------------
| a                   | b                  | 1         |
| c                   | d                  | 2         |

Note that "a", "b", "c", "d" are not the constant keys, they are variable. I know that "dataSrc": "data" is the must here but I am unable to parse the nested object. Any advice ?

Answers

  • mirfilipmirfilip Posts: 2Questions: 1Answers: 0

    The formatting has been stripped. I would want to show two records: (a, b, 1) and (c, d, 2)

  • allanallan Posts: 61,970Questions: 1Answers: 10,160 Site admin

    You would need to reformat the data into an array. DataTables currently does not support using objects as a data source for the whole table, only for individual rows. You must use an array, with one entry for each row in the table.

    Allan

This discussion has been closed.