Access nested dynamic object

Access nested dynamic object

kenghengkengheng Posts: 2Questions: 1Answers: 0
edited April 2021 in Free community support

Would like to know how do I display the dynamic nested objects for: new_values & old_values as below ?

===datatable===

{
  "draw": 0,
  "recordsTotal": 7,
  "recordsFiltered": 7,
  "data": [
    {
      "id": 61,
      "user_type": "App\\User",
      "user_id": "7",
      "event": "updated",
      "auditable_type": "App\\Personal",
      "auditable_id": "41",
      "old_values": {
        "identification_number": "828111111"
      },
      "new_values": {
        "identification_number": "98190000"
      },
      "url": "http://svr.local/personal/41",
      "ip_address": "127.0.0.1",
      "user_agent": "IE",
      "tags": null,
      "created_at": "2021-04-17T13:58:10.000000Z",
      "updated_at": "2021-04-17T13:58:10.000000Z"
    },
    {
      "id": 41,
      "user_type": "App\\User",
      "user_id": "7",
      "event": "updated",
      "auditable_type": "App\\Company",
      "auditable_id": "50",
      "old_values": {
        "registered_address1": "495 Hague Street",
        "registered_address2": "Ex occaecat autem ex",
        "registered_postcode": "Reprehenderit conse",
        "registered_state": "Quas qui incididunt",
        "registered_country": "AO"
      },
      "new_values": {
        "registered_address1": "NORTH BRIDGE ROAD",
        "registered_address2": "14",
        "registered_postcode": "188778",
        "registered_state": null,
        "registered_country": "SG"
      },
      "url": "http://svr.local/company/50",
      "ip_address": "127.0.0.1",
      "user_agent": "IE",
      "tags": null,
      "created_at": "2021-04-14T13:21:11.000000Z",
      "updated_at": "2021-04-14T13:21:11.000000Z"
    }
  ],
  "input": []
}

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    See if this example helps.

    Kevin

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Kevin's answer looks good to me. If you want further support, please explain why that wasn't helpful.

    Colin

  • kenghengkengheng Posts: 2Questions: 1Answers: 0

    Hi Colin,
    Kevin's answer is for fixed json objects, my json objects are dynamic.

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    I'm not clear on what the difference is there. serverSide expects the data to be in a format in response to the ajax request, and Kevin explained how to parse that data.

    It might be worth reading the docs. The protocol is discussed here. Also see examples here.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921
    edited April 2021

    You can access the object, new_values for example, inside columns.render to display the object data. Use the for loop of your choice to iterate the object and build a string that will be displayed, for example:
    http://live.datatables.net/fatunede/1/edit

    You will want to read the columns.render docs and the Orthogonal data docs to understand the example.

    Kevin

This discussion has been closed.