How to load subtable data just once for multiple child rows
How to load subtable data just once for multiple child rows

Hi, please check out my running sandbox version of my data entry work here: pid2.lindenlion.net/reports.html
I have a childrow table for each patient which filters relevant rows from another table by searching for the patient id in the background when the child row is opened. This works. Now I try to implement an expand all button, and it works, but it's soo slow, I was hoping I could make it faster. My guess is, that for every child row the whole table is requested through ajax, which is very stupid, because it would mean downloading the same table over 200x. Is there a way to fetch the whole table just once and then re-use this data while expanding each child row?
This question has an accepted answers - jump to answer
Answers
You are doing that yourself with your "sub_DataTable" function.
Yeah I got that
Just looking for help, how to handle it differently.
I'm not very good at programming, I just need this as a tool to get my data entry job done. I appreciate your help though pointing me in the direction that I need looking at. Does anyone have a suggestion on how to modify the sub_DataTable function? Can I pass the table as an argument to the function and then use that instead of fetching the data on expansion of every row?
This blog shows a technique to load each child row by passing an
id
inajax.data
to filter the ajax response.https://datatables.net/blog/2019-01-11
This should result in the ajax response containing only the data for the child row. If displaying all child rows is still too slow then you will need to employ techniques to limit the child row display to the page being displayed instead of all. I would probably look at setting a flag in the Show All and Collapse buttons and simply call
draw()
, ie,table.draw();
. Then us thedraw
event to determine if the Show All or Collapse button was clicked and useselector-modifier
to select only the visible rows to expand, ie,table.rows( {page:'current'} ).every(function(){
. If you need help with this please post your updated example.Although this example is for search child rows it should give you an idea of what to do:
http://live.datatables.net/begujizo/1/edit
Kevin
Your 'Show all histories' function calls "sub_DataTable" for every row found.
For future reference, it helps if you explain exactly which file we need to be looking at.