Search in rows already hidden by filter

Search in rows already hidden by filter

andytuandytu Posts: 4Questions: 2Answers: 0

Hi everyone:
I am using DataTables to show the accounting accounts of my company(I have a total of 9643 records), and I have already filtered out the ones beginning with '704', '705', '811', '950' and others (using search()). That gives me a total of 3425 hidden rows. Now I want to unhide some of them. I've found out how to get the hidden rows by using rows() and passing {search:'removed'} as a parameter. I already unhide them using pure javascript, but it is a bit slow when dealing with 3000+ rows.
So the question is: Is there a way to apply some of the API methods (like search()) to search between those hidden rows?
Thanks in advance,
Andy

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Answer ✓

    Currently no - there isn't an API to toggle the filtering state of a row, although that is a nice idea and possibly how I could implement filtering in DataTables in future. Certainly for 1.11 it needs an overhaul!

    The search applied is currently reapplied on each full draw (that probably won't change) so whatever is searched on by search() will be reapplied. Long way of saying, if you want to use the built in search options, you would need to update your call to search() to match your new requirements.

    Allan

  • andytuandytu Posts: 4Questions: 2Answers: 0

    Sorry, looks like I didn't explain myself so well: I can hide and unhide the rows, using a hidden column with the visible indicator and row().invalidate(). But I have around 3000+ hidden rows, and iterate over them using pure javascript is slow. I'm just wondering if there is a way to use the DataTables.Api object returned by rows({search:'removed'}) and iterate over it using some API method. I suppose I have to keep using javascript cycles :D. I appreciate the help, Allan, looking forward 1.11. Kudos!

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Answer ✓

    Oh I see - that's a nice way of doing it :-)

    You could use rows().every() to loop over the removed rows:

    table.rows( { search: 'removed' } ).every( function () {
      ... update data
    } );
    table.draw();
    

    Allan

  • andytuandytu Posts: 4Questions: 2Answers: 0

    Yep, that's what I'm already doing, the only problem is when there are thousands of hidden rows :D. But, it works, so...
    Thanks for all the help, keep all the good work up!

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    The part that slows down the every function is that it creates a new API instance for each call - with the data and context appropriately set for the row in question.

    Indexes would be faster (looping over rows().indexes(), but you would still need to use the API to modify the data. It is possible that will be faster since there is less context switching. If you try it, I would be interested to know the result!

    Allan

This discussion has been closed.