The question
Is there a way to programmatically retrieve only the rows witch match some specific criteria - for example rows having specific indexes?
The API has a method - rows(), which results can be manipulated a little by providing a selector-modifier argument. However, using it I am able to use the current table search at most, not a custom one.
The problem
For better understanding, I'll provide more details about what I am trying to achieve.
I am using the Select extension. I would like to select some rows at once using an external trigger. Now I do it like this:
myTable.rows().every(function () {
// ...
// Check if the row should be selected and if so:
this.select();
// ...
});
However, this causes firing of the same number of select events on the table as the number of selected rows. I have a handler bound to this event, which performs a request to an external API, based on the selected rows. Since I cannot discern which select was the last one, my handler ends up spamming the external API needlessly because of the number of events.
Solutions
- Retrieve only matching rows and use
rows().select()on them.
I think that would be the best solution, because the select event would be fired only once. However, I have no idea how to do it - hence this question.
- Prevent the handler from calling the external API until the selecting process is finished.
I thought up two hacky solutions which I'll use as a last resort:
Not use an avent handler at all and simply call the API after the
rows().every()loop - I still have to use the handler to deal with manual row selection, but that'll probably do.Iterate through the rows twice - first time to check which row would be the last to be selected, then disable the handler, do a second loop which actually selects the rows, and enable the handler before selecting the last row
I hope the whole question isn't too confusing. To be clear - the thing I would like to find an answer for is the question on the top, in italics.