-
Notifications
You must be signed in to change notification settings - Fork 490
Bug when sort on filtred data #289
Comments
Can you provide your full example? |
Thanks for your answer I would like to show you my code too, but it's too long as i display 20 tables in a single html file. I can provide a zip file, but i don't see any attach file option :( |
Ok here's a table example
then the html code
As you can see, there are two filters. On by "annee", and the other (myFilter) is by a field "trimestre". The problem happens when i use the "trimestre" filter. For example, When i click on a "trimestre" choice, i got fewer results, then i click on a table header, the "trimestre" filter is loosed, and i got more results. |
When i first load the page, the filter "annee" has the value 3 by default. so all the data having the field "annee":"3" are shown. Then for example, if i change the filters values, i got new data displayed, and then i click on a table header, what happens is the data that was displayed when i first loaded the page are shown. Si i have to figure out, how to tell Datatables that the data displayed changed since i changed the filters, and that Datatables has to sort the filtered data, and not those displayed when the page is loaded. Any hint ? please! |
I used http://debug.datatables.net/ (Datatables debugger) to see what's going on, and indeed, the version sent to Datatables is the one when the page is loaded. Everytime the table changes, Datatables doesn't detect that. Any idea on how we make it detect the change with angularjs please ? Thanks |
Can you put your code in a plunker? It will be easier to debug your issue. |
Hey, i believe we are battling against a similar issue I've created a codepen http://codepen.io/forres/pen/WvbwPq?editors=101 |
Yep this looks to be exactly my problem. |
I managed to isolate the issue The point is we where using $scope to save our different data & configurations, and I believe that by using "THIS" as the main variable, yo manage to keep the angular $digest working correctly. I cant really say for sure, i'm not that much of an angular dev. |
@l-lin ok you can see my bug here : http://codepen.io/anon/pen/RPNZXp?editors=101 When i first load the page, i have 4 rows, then i click on "Avril - Juin", i obtain 2 rows, then i try to sort =>back to 4 rows |
Up Do you think it's possible to fix this bug ? thanks |
You need to differenciate the sorting from Angular and from DataTables. When you update your filter, only the array in Angular is updated. However, the data stored in the DataTable is not updated. So after you updated your data in your angular controller, you will need to rerender your datatables. |
That's weird, your pen works perfectly, but when i use the same fixes in my code (where i have 20 tables), i got this error everytime Error: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node. Gosh i hate it when i work with something i don't master ... Thanks a lot l-lin |
I'm trying to debug, and i noticed that the problem is caused by the presence of multiple tables in the same page.
This line is called when the line the table variable isn't pointing the table on which i applied a filter. It points to another table (a hidden one) and everytime i try to filter data, this wrong table is deleted from the DOM And settings.nTableReinsertBefore is pointing on this element :
And this element isn't placed near the table on wich i applied a filter neither! I tried to add an id on each table. changed nothing. Could this be a bug in Datatables ? I put my whole code here (a zip file containing html and scripts ..) https://drive.google.com/file/d/0B2RwGZgU4S4YRjdRMlJLN0RLd0U/view?usp=sharing I applied l-lin fixes only in one table : click "DÉPENSES DE L'ORGANISME PUBLIC" and then click "Frais de déplacement" Thanks a lot |
Here is a pen to see that the bugs is not really fixed when i have multiple tables on my page http://codepen.io/anon/pen/eNNVgo?editors=101 When using filters on the first table it works, but when i use filter on the second table, and then i sort, nothing works. And when i tried debuggin on the jquery-datatables.js script, i noticed that the table passed to the function insertBefore is not the right one |
That's because the So to answer your question, it won't work with multiple tables on the same page, yet. |
Ok, i'll wait for the next version including the bug fix then. Thanks a lot! |
I just tried the solution, with dtInstance, changed nothing for me http://codepen.io/anon/pen/eNNVgo?editors=101 |
I corrected your pen. |
hi,
I have a table, containing some data. And i have two filters ont the data
example of table définition :
<table datatable dt-options="dtOptions" ng-repeat="x in accueils | filter:{annee:annee.id} | filter:myFilter as results" ng-if="$first">
So when i first load my page, i have 10 rows in my table, and the sort works good.
Then, i click on a filter button, so instead of having 10 rows, no i have 5 rows, then i click on any table header to sort the column, and then i have the problem as the number of rows become 10 again, the filtering is loosed, any idea how to keep the filter value ?
Thanks
The text was updated successfully, but these errors were encountered: