problem with $.fn.dataTable.ext.search.push and sort
problem with $.fn.dataTable.ext.search.push and sort
Link to test case: http://testdtraphu.ddns.net:10049/portables.php
Description of problem:
My problem is strange:
I am using $.fn.dataTable.ext.search.push to set up filters on articles. it works wonderfully ... but when I apply one of my filters the good articles appear then when I sort them by price or by description it is not the same articles which appear anymore ...
Even stranger, when I sort before applying my filters and then apply one of my filters, the articles displayed are directly bad ?? I do not understand...
This question has an accepted answers - jump to answer
Answers
This is your plugin code:
You are using the
loop
parameter to directly access the Datatables data cache. The loop parameter is the wrong parameter to use as its the "This is the loop index that DataTables uses internally to loop over the rows in the table.". This is form the Search Plugin docs. This is causing the randomness you are seeing. Use theindex
parameter instead which is the row index for the data.Its not recommended to access the data cache directly, ie,
settings.aoData[loop].nTr.attributes[1].value
. You should use the Datatables APIs instead. See this example:http://live.datatables.net/cerudesi/1/edit
It access the API and uses
cell().node()
to get the cell's HTML then checks to see if it has the classdirector
.Change
api.cell(index, 1).node()
toapi.cell(loop, 1).node()
and you will see the same randomness. Also the console output will show you the difference between theloop
andindex
values.Kevin
dear Kevin,
it works perfectly ... 1000 thanks