Nested tables from nested objects (JSON)

Nested tables from nested objects (JSON)

alfablacalfablac Posts: 2Questions: 1Answers: 0

So, I tried a few of the available examples in the docs, but I couldn't advanced in the child rows section. I think I'm a bit confused with the concept of child rows/nested objects, where the docs show child rows as just an extension (more info) of the same object, that can be nested in the JSON response.

For my data, In summary, objects are documents and these documents may or may not have attached documents (it's simply an object with nested objects of the same type). Here it's a slice of the data:

            "codDoc": 1,
            "title": "Parent 1",
            "dateCreation": "1999-01-01T00:00:00",
            "childDocs": [
                {
                    "codDoc": 2,
                    "title": "Child of Parent 1",
                    "dateCreation": "1999-01-01T00:00:00",
                    "childDocs": null,
                    "parent": false
                },
                {
                    "codDoc": 3,
                    "title": "Child of Parent 2",
                    "dateCreation": "1999-01-06T00:00:00",
                    "childDocs": null,
                    "parent": false
                }
            ],
            "parent": true

The output should be a table that given the clicked element id (codDoc) I can show all attached documents of that parent.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,332Questions: 26Answers: 4,774
    Answer ✓

    If I understand your question you just need to loop through the childDocs array and build the HTML the way you want it to look. Here is an example using your data:
    http://live.datatables.net/wodevate/1/edit

    Kevin

  • alfablacalfablac Posts: 2Questions: 1Answers: 0
    edited December 2018

    Hi Kevin.

    I think that will do it.
    It's a .NET MVC project, so I feel it's easier to me to at least build the parent rows in the CSHTML page so I can easily get the parent document key for that row... but I think the iteration over the childDocs is what I needed to see to continue my project.

    Thanks!

This discussion has been closed.