[DT 1.9.4] How to get the subset of rows currently being displayed to the user?

[DT 1.9.4] How to get the subset of rows currently being displayed to the user?

junaedjunaed Posts: 18Questions: 7Answers: 0
edited October 2015 in Free community support

Suppose I have 1000 rows, but showing only 10 per page. Now how can I get the 10 rows that the user is currently seeing? I see that I can use _ (underscore) method like this: dataTable._('tr', {"filter":"applied"});, however that works only if I am filtering (using the search box), otherwise it returns all the 1000 rows. Without doing filter, is there any way to get the set of rows that are currently being rendered on current page?

Thanks a lot.

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited October 2015 Answer ✓

    Should be able to use the selector-modifier, Such as..

    table.rows( {page:'current'} ).indexes();
    

    Heres a quick example, which just gets the indexes of the visible rows.. (Click the button at the top, then change the length, or filter, then click it again)

  • junaedjunaed Posts: 18Questions: 7Answers: 0

    Thanks a lot jLinux, I was able to do this:

    dataTable._('tr', {"page":"current"});
    

    I can even combine the modifiers!!

    dataTable._('tr', {"page":"current", "filter":"applied"});
    
  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Very nice :)

  • junaedjunaed Posts: 18Questions: 7Answers: 0
    edited November 2015

    Ok, so I got some update. The above method works "all" the time except in "page.dt" handler (which fires during page change event). The following gives me empty:

    dataTable.on('page.dt', function(e,settings){
        dataTable._('tr', {"page": "current", "filter": "applied"}); //returns empty []
    }
    

    On the other hand, this returns full set of data (given no filter is applied)

    dataTable.on('page.dt', function(e,settings){
        dataTable._('tr', {"filter": "applied"}); //returns full set of data
    }
    

    So clearly, "page":"current" does not work during page change. Any ideas how can I achieve that?

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    I cant seem to replicate the issue..

    http://live.datatables.net/jofazibi/5/edit?js,output

    Can you update that to replicate what you're seeing? If you cant, then im sorry, cant do much to help

  • junaedjunaed Posts: 18Questions: 7Answers: 0
    edited November 2015

    Thanks jLinux for the demo, may be its working for you because you are using the latest version of datatable. I am using 1.9.4, and its not working as expected. Here is a link:

    http://live.datatables.net/yanugepo/1/

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015

    That doesnt show the indexes, it shows the entire row in the span (SS), and it only shows it when I change pages, it should do it on dt.draw

    And Im not sure how much help I can be with version 1.9.4, you should really be using the most current stable release.. why cant you update that?

  • junaedjunaed Posts: 18Questions: 7Answers: 0

    I had to do that in "draw.dt" to make that work. Its not optimal (as we don't need to do those as frequent as per draw, only during page change is enough), but works.

    Updating is not an option now, however we are considering it.

    Thanks a lot for your time and help, jLinux.

This discussion has been closed.