Parent / child using JSON

Parent / child using JSON

lenamtllenamtl Posts: 265Questions: 65Answers: 1
edited November 2022 in Free community support

Hi,

I'm looking for an example of Parent / child I'm using PHP & JSON (no DB, no editor).

I would like to reproduce this kind of tables https://datatables.net/blog/2016-03-25

For example: the user select a company in parent then it display all locations in child.

I would like to use
var dataSet = [ ]

or this is not possible

  {
     "data": [
           {
                    },
     ]
   }

Thanks

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,141Questions: 26Answers: 4,736

    To make sure I understand correctly. You want to store the child table data in the variable dataSet. When the parent row is clicked get the pertinent data from dataSet to display in the child table. If this is correct then yes you can do that.

    You will need a unique piece of data in the parent that can be used to find the child data in dataSet. If dataSet is an array then you will need to loop through all the elements to find the child data. Not efficient but could work with small amount of data.

    I would look at making it an object the the keys being the part to match from the parent and the value is an array of all the rows to display.

    Kevin

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited November 2022

    Hi,

    I can use any json / text forma.
    The data are in excel file (around 400 lines) so I can transform to other format.

    I do not use any DB for this project so any example that can work without a DB would be ok for the needs.

    If possible without Ajax.

    Thanks

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    You could absolutely do this without a database (and without Editor if you don't want editing). Basically follow along with the blog post you linked to (missing out the Editor parts), but instead of fetching the data from an Ajax source, you would need to query wherever you are storing your data and feed it into the child DataTable that way (e.g. data rather than ajax).

    Allan

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1

    Hi,
    Can you provide a basic example Parent / child that use data or dataset.
    I would really appreciate.

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin
    Answer ✓

    Here is a simple example: http://live.datatables.net/zamoxabo/1/edit .

    Allan

  • lenamtllenamtl Posts: 265Questions: 65Answers: 1
    edited November 2022

    Hi @allan

    I have many columns and rows, so I'm wondering which method would you use to convert excel data to this data format with parent / child?

    Thanks

  • allanallan Posts: 61,438Questions: 1Answers: 10,052 Site admin

    It isn't something I've done before, so I'm afraid I can't really advise on that. It will depend on the amount of data and the format it is in, but perhaps you could parse the data out of the XSLX file (SheetJS for example can do that) and then convert it to JSON.

    Allan

Sign In or Register to comment.