Unable to get column search working
Unable to get column search working
mcevikce
Posts: 4Questions: 1Answers: 0
I am using Datatables 1.10.0. I have a table with 55 rows with 12 columns. I am trying to execute a search on column 9 which should only match two rows. Then I want to delete those rows. But for some reason all the rows are returned based on the search I perform. Here is the code:
oCusipTable.columns(9).search("2010", true, false).rows().remove().draw();
Result of the search is 55 rows. Should be only 2 rows.
This discussion has been closed.
Answers
I don't believe the
search()
function is meant to be used this way. I thinkfilter()
is meant for this. However......I tried to get
filter()
to work, but had no luck. However I was able to get the functionality you want with a little more effort (demo)Would that work for your situation?
@rhino is correct - that isn't really how it is designed to work - although if you were to add
{ search: 'applied' }
into your rows selector it would remove the two rows and you'd end up with nothing displayed (since the filter is sill applied and the rows have been removed).rhino's solution is a nice way of doing it (@rhino kudos for taking the time to create the code!).
Another option is to use the
filter()
method to reduce the data set (after arows().indexes()
call (and getting the data in the callback to check if the data for the index matches. That's ultimately probably the best way to do it, but it is basically the same concept as rhinos solution.Allan
Hey @allan, here's what I was trying to do with
filter()
:(and here's the non-working demo)
What's the right way to do this?
Here is how I would suggest doing it: http://live.datatables.net/rilebop/4/edit .
The basic problem with your code above is that the
filter()
function is returning the data from the row, not the indexes. Note that I usedrows().indexes()
rather thanrows().data()
. The data is gathered in the inner function and changed.For completeness I've also used the DataTables API registration mechanism.
Ultimately I want to make the selector functions have a function option so this could be made a lot more elegant - just a single line (with the closure function of course).
Allan
rhino/allan,
What you have suggested worked great. Thank you for the prompt response and help.