How to load subtable data just once for multiple child rows

How to load subtable data just once for multiple child rows

alchemialchemi Posts: 11Questions: 3Answers: 0

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

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    My guess is, that for every child row the whole table is requested through ajax, which is very stupid,

    You are doing that yourself with your "sub_DataTable" function.

  • alchemialchemi Posts: 11Questions: 3Answers: 0

    Yeah I got that :blush:
    Just looking for help, how to handle it differently.

  • alchemialchemi Posts: 11Questions: 3Answers: 0

    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?

  • kthorngrenkthorngren Posts: 21,144Questions: 26Answers: 4,918
    edited April 2019 Answer ✓

    This blog shows a technique to load each child row by passing an id in ajax.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 the draw event to determine if the Show All or Collapse button was clicked and use selector-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

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    edited April 2019

    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.

This discussion has been closed.