Sort on Ajax-driven dynamic table
Sort on Ajax-driven dynamic table
Link to test case: I can't link as this is within an app. We can create a mockup if really necessary. Hoping the description might lead to a solution.
Description of problem:
Context:
I have a table that we filter the data with checkboxes and it reduces the number of rows displayed, narrowing down choices. And each checkboxes trigger an ajax call to return a fresh bunch of rows.
The problem:
When we click on the column header to sort the table with DataTables. the sort returns ALL the rows unflitered (exactly what was loaded on page load).
How can we prevent that, and have the sort only sort what is actually displayed once we filtered the table with the checkboxes?
Here is a snapshot:
Answers
How are you doing this? Maybe you can start by posting the code used to perform this function. Likely we will need to refactor it to use Datatables API's for the table updates.
Kevin
This is the main page. The Ajax return is at line 178.
This is the javascript that returns the subset of data based on the checkboxes.
This is the php file called by ajax:
AND this is the CODE called by the require:
I gather that this is the code executed to update the table via the checkbox?
Datatables won't know about the changes when directly updating the DOM. Datatables has a data cache which it uses for sorting, search, etc. When updating the table you will need to use Datatables APIs to update the Datatable data cache. Here are some options:
rows().invalidate()
destroy()
ordestroy
clear()
followed byrows.add()
Kevin
I am trying to use any of your suggestions but I am not sure where and how to integrate them...here is what I tried and it just prevented my script from even refreshing based on checboxes.
Where and how should I use the code you suggested above?
code:
Seems like that would be a good place. Its hard to say without seeing it.
Do you get errors in your browser's console?
You've posted a lot of code which is hard to imagine whats happening. Please post a link to your page or a test case replicating the problem so we can help diagnose.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
No.
I'm working on that.