Identify Row on Current Page

Identify Row on Current Page

shmoeazshmoeaz Posts: 2Questions: 1Answers: 0

I have an external action that requires me to loop through all the rows in my table and inspect the data. However, I also want to manipulate the rows that are currently visible or displayed on the current page.
Is there a way to test the row to see if it is currently visible/on the current page?

    table.rows().every(function(idx, tLoop, rLoop){
        var data = this.data();
        // ... do something
        if (this.isOnCurrentPage()) {
            // ... do somehting more
        }
    });

isOnCurrentPage() is just an example of what I'm trying to do. I don't know if I could use a selector some how or something of the like.

Any ideas?
Thanks

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    edited May 2021

    You can use a separate rows().every() loop just for the rows on the page using the selector-modifier of {page: 'current'}, for example:

    table.rows( {page: 'current'} ).every(function(idx, tLoop, rLoop){
        var data = this.data();
        // ... do somehting more
        }
    });
    

    You can remove the if statement from the other loop.

    Kevin

  • shmoeazshmoeaz Posts: 2Questions: 1Answers: 0

    I think I found an appropriate solution using the page info and the rowLoop index.

        var currPageStartIdx = table.page.info().start;
        var currPageEndIdx = table.page.info().end;
        table.rows().every(function(idx, tLoop, rLoop){
            var data = this.data();
    
            if (rLoop >= currPageStartIdx && rLoop < currPageEndIdx) {
                console.log("*** row on current page");
            } 
        });
    
  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    Clever solution :smile:

    Kevin

This discussion has been closed.