Can a child row be from a related table(s)?
Can a child row be from a related table(s)?
I have too much info to display in a single datatable view and would like to have a child row(s) from a related table. I've seen an example where this is done with data from the same table. However, I'd like to pull the child row data from a second table. Probably similar to an Order / Order Details type scenario. I have a table where my orders are stored and a second table with order details (and a third table with products).
Can someone help point me in the right direction as to how to accomplish this? I'm new to DataTables and Editor.
Thanks.
This question has an accepted answers - jump to answer
Answers
Is the information to be shown in the child table from a
leftJoin
action (docs). If so, the approach in the example you allude to is the way to go - just use the information from the joined table in the child row (you don't have to show all fields in the DataTable!).Allan
Allan,
I am using a couple of left joins (one is used only to get a name from another table based on an id for display purposes).
My primary goal is to display Table A in a DataTable/Editor along with a single or multiple associated records in Table B as child rows. It would be ideal if all data could then be edited in all rows.
Thank you.
Okay, for that you probably need to create a new DataTable and Editor instance in the child row. I'm afraid I don't have a direct example of that, but basically you need to give the child renderer the HTML for the table and then initialise it as a regular DataTable.
You might also be interested in this blog post. It isn't a perfect match for what you want, but it does overlap somewhat.
Allan
Allan,
Thank you for the response and blog post link. I'm probably about 10% familiar with all of DataTables/Editor at this time and not sure how to create a new instance of DataTable/Editor in a child row. Not sure of the renderer as well.
Allan,
In the blog post under the "Wiring it together" section where should the provided code be placed?
Allan,
I'm trying to replicate what you have done in the blog post wth my two tables, but not yet realizing success. I've compared what the blog post has to what I have at least a dozen times and cannot notice any difference. Can you suggest a way see what is being posted from the HTML file to the server-side PHP? I can get my Parent table to display all data, but am receiving no associated data in my Child table. It's as if the ID I'm using to associate both tables is either not posting to the server-side PHP file for some reason or I've made some other coding mistake I cannot see at the moment.
Thank you.
Use the developer tools in your browser. Right click and select "Inspect", then click the "Network" tab and make the Ajax request. You'll be able to see the parameters sent to the server under the "Headers" sub-tab.
If you have a link to the page I would be happy to take a look and see if I can spot what is going on.
Allan
Hi Allan,
I'll PM you the details on how to access the files in question.
Thank you.