Loop Through Visible Rows

Hello community, I have a business use case where I need to loop through all of the visible rows and update the data on just those visible rows. For example, I would like to have a column with check boxes and include buttons on the page for Select All, Select Visible, Select None. The select All and Select None part of my code is complete and works great, but I need to be able to have the use select all visible.

When the user filters down the table or hides rows, I will have them click a button that says Select Visible and it will loop through and change the check box values to true, and re-render the table. Is there an object that contains just the visible rows?

Any suggestions on this topic would be greatly appreciated. Thanks!

Hi @ryan.reed

I am afraid that this won’t be easy as (I assume) we would need to support non-consecutive row select which we do not support yet. However I have managed to create a demo that may come in handy, please take a look at it http://jsfiddle.net/handsoncode/fpwhvadp/1/

1 Like

@aleksandra_budnik, thank you very much for the reply. I was able to take your code and make a slight modification for what I was requesting. The new snippet of code below will loop through all of the visible rows and update the checkbox. The only issue with it is if you have a large number of rows for it to loop through it can take a long time to process. There is probably a more efficient way of writing the snippet below, but this will work for now. Thanks!

 var rows = [];
 for (var i = 0; i < hot.countRows(); i++) {
   rows.push(i);
 }
 for (var j = 0; j < rows.length; j++) {
    hot.setDataAtCell(j, 0, true);
 }

Glad to hear that it works.

I think that you could also try to use the loadData() to do the same, however, that would require the main algorithm to be rewritten to give us some kind of scheme.

Here is a comparison between the loadData() and setDataAtCell() that I’ve made some time ago. Both methods do the same job however when there’s more data setDataAtCell is few times slower.

ps. In the end of June, we will start to work on the eco-rendering that will boost the performance for all the methods related to checking values or metadata https://trello.com/c/m9KTygSV/80-refactor-re-write-of-renderers-eco-rendering

1 Like