I am fetching data from database to view.
I am having 3 different datatables with some filters.
Loading all together taking about 16 seconds. I need to first load the 1st datatable and after that I need to load the other 2 one by one.
I have tried ajax to fetch data after page load but I don't know how to write function in controller to load 1st datatable and load other two after sometime / some conditions, because for these 3 datatables I am fetching data from same tables comparing with some other tables but in the view I am doing some filtering so it takes a longer time to load fully.
@sin2san What exactly are you trying to achieve? You want to load the 1st datatable, when that's finished the 2nd and after that the 3rd? How do they differ? Especially regarding the query parameters.
There is no difference in Query parameters.
1st datatable is fetching student history of courses
2nd datatable is fetching student attendances
3rd datatable is fetching their assessment results.
1st datatable loads data from one table (student_course_table).
2nd datatable loads data from two tables (student_course_table) and (attendance table)
3nd datatable loads data from two tables (student_course_table) and (assessments table).
1st datatable is ok as it loads from student_course_table the data fetched directly and there's no filtering so it loads fast.
for 2nd and 3rd datatables I am having more conditions inside like if else, foreach, for so it take long to load.
What I am trying to achieve is 1st I need to load 1st datatable after that 2nd & 3rd.
All the three is for report purposes with comparison so everything should be in the same page.
@sin2san Maybe you should use three different endpoints then, one for each datatable and trigger the loading of the 2nd and 3rd datatable after the AJAX request of the 1st has finished. That feels a bit dirty tho. Maybe it would be cleaner if you work with tabs/dropdowns/accordions on the same page. So the 2nd or 3rd datable is fetched if the user wants to look at it.
Yes. I am trying to do filtering in view rather than fetching data after filtering.
Because most of the data are need to be conditionally used in view.
So I am fetching the data and filtering it in view.
All the tables involved having relation with each other.
so I am having only one function in controller and fetching the data and filtering in the view based on conditions.