2nd AJAX call for Child Table

2nd AJAX call for Child Table

dpanscikdpanscik Posts: 201Questions: 46Answers: 0
edited January 12 in Free community support

I would like a 2nd AJAX call to populate a child table just like in this example;

https://datatables.net/blog/2017-03-31

However this example comes up short of what my goal is.

The 2nd AJAX this example loads for the child table is preformatted HTML in a details.php file.
Here is a direct link to that PHP HTML file that populates the child table.
https://datatables.net/media/blog/2017-03-31/details.php

What I am trying to do for the 2nd AJAX call is to get normal AJAX data looks like;
{
"data": [
{
"id": "1",
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011\/04\/25",
"office": "Edinburgh",
"extn": "5421"
}
]
}

and use that data to populate into a child table

Is there an easy way to build from the 2017 example to show me how to accomplish this goal?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908
    Answer ✓

    You are free to do whatever your solution requires. The format() function can be used to build anything you like. In fact it doesn't need to be called format :smile:

    The blog you linked to is returning a JSON response. Use the browser's network inspector to see the response and you will see something like this:

    {
        "html": "Details for <b>Ashton Cox</b><br><br>Full information could be derived from a database and potentially complex interactions such as charts, DataTables or other controls could be shown if required. In this demo only this summary is returned."
    }
    

    The blog is simply returning the html object as the HTML to display in the child row. You can parse a more complex JSON response into the desired HTML output you would like.

    Another option is shown in this blog. It shows how to create child rows that contain a Datatable and use Editor with the child Datatable. You can ignore the Editor config if all you want is a Datatable.

    Kevin

  • dpanscikdpanscik Posts: 201Questions: 46Answers: 0

    Thanks Kevin. Your thoughts pointed me in the correct direction. I figured it out and successfully hand coded a child table using the format subroutine.

    The work flow here in the blog you pointed out seems like the better way to do this, where you let datatable do the code writing for the child table.

    Im going to play around with this concept a little and see what I can figure out.

Sign In or Register to comment.