Sliding child rows, how to change the format function to work with nested json ?

Sliding child rows, how to change the format function to work with nested json ?

mlotfimlotfi Posts: 60Questions: 5Answers: 0

This page show a nice sliding row :
http://datatables.net/blog/2014-10-02

let say we have a nested json :

{
  "data": [
    {
      "name": "Tiger Nixon",
      "position": "System Architect",
      "salary": "$320,800",
      "start_date": "2011/04/25",
      "office": "Edinburgh",
      "extn": "5421",
      "agencies": {
        "name": "agency2",
        "name": "agency5",
        "name": "agency24",
      },
      "globals": {
        "name": "global42",
        "name": "global13",
        "name": "global4",
      }
    },
    ......
    ......
    {
      "name": "Donna Snider",
      "position": "Customer Support",
      "salary": "$112,000",
      "start_date": "2011/01/25",
      "office": "New York",
      "extn": "4226",
      "agencies": {
        "name": "agency23",
        "name": "agency56",
        "name": "agency2",
      },
      "globals": {
        "name": "global2",
        "name": "global13",
        "name": "global45",
      }
    }
  ]
}

Replies

  • mlotfimlotfi Posts: 60Questions: 5Answers: 0

    How to change the format function in that slide example to work with this json format ?
    Thanks

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    The format function is just being passed in the data obejct for each row. So you might use data.agencies.name (btw your JSON looks very odd as name in agencies and global is repeated multiple times).

    Allan

  • mlotfimlotfi Posts: 60Questions: 5Answers: 0

    Thanks allan,

    I think I should put an array instead of name in agencies and global :

    "agencies" : ["agency23", "agency56"]

    "globals" : ["global2", "global13"]

This discussion has been closed.