Nested json question

Nested json question

gunnargjgunnargj Posts: 1Questions: 1Answers: 0

Hi
I have nested json like this.

Can the result in the table be:
2019, Item 1, 89929
2019, Item 2, 5414

I only get the year once with this code and nothing for the children:
"columns": [
{ "data": "date" },
{ "data": "root.name"},
{ "data": "root.count"},
],

Answers

  • kthorngrenkthorngren Posts: 21,172Questions: 26Answers: 4,923
    edited June 2020

    Datatables expects each row to be it's own array element. For each root element to have tis own row your data structure would need to look more like this:

    {
        data: [
            {
                date: 2019,
                name: Item 1,
                count: 89929
            },
            {
                date: 2019,
                name: Item 2,
                count: 5414
            }
        ]
    }
    

    More info can be found here:
    https://datatables.net/manual/data/#Data-source-types

    Kevin

This discussion has been closed.