Server-side processing DataTable with row details - script
Server-side processing DataTable with row details - script
Hi, I have DataTables table with 7 columns and server-side processing and I tried to load another 15 columns and display them in the row details. It's working, but the execution of SQL query takes around 30s. All indexes and other aspects were checked, the query is too complicated
I think the only way is to load the additional data after click on the row. I tried to implement this https://datatables.net/blog/2017-03-31, but there is no sample php script which is used in the ajax request.
Can I use the same script as server_processing.php ? I've tried it, but everytime I click on the row, I get "Loading..."
Thank you for any advice.
Answers
Perhaps you can show me the query being executed for your server-side processing? 30 seconds is a huge amount of time to get 10 records (assuming default paging).
No it needs to be a different script (or use a condition to serve a different response). Here is the PHP for that example in the blog:
In the real world (like you are doing) you'd want it to connect to the database to get the row details.
Allan
Hi Allan, thank you for the php. It was very helpful. I was able to send the id to another php script, get the data and send back another json. Now I have 1 ajax with url: "scripts/server_processing.php" to load the main table and another ajax with url: "scripts/details.php" to load the details which is executed after click on a row.
Now I'm struggling with displaying the data from details.php in the row details. When I used the previous (slow) solution with just one ajax call to load, I used the function(d), which was great to work with. Now I added the same function, but the data I can show are from the main table, not the details.php. How can I force the function(d) to use data from the second ajax?
My JSON from details.php:
And here is my code:
And here is the sql query:
The problematic part is the group_concat and GROUP BY, but I need them to have unique ID in every row, because there is one to many relationship between table1 and table2.
The key thing about Ajax is the first letter in the acronym - "Asynchronous". Your
format
function above is returning before the Ajax call is complete.You need to do something more like this for it to work.
Allan
Thaks Allan, I rewrited the code as you adviced. Problem is, that html is generated in the php script, which connect to the database and then send to index.php the json encoded "html".
My details.php script returns JSON in this form:
and I need to show these values in the index.php. I'm not very familiar with javascript to modify it by myself. I think I need to modify the "success:" part. Please, can you show me how to display data from the JSON above in this function?
}
Thank you