How do i loop through rows on current page only

How do i loop through rows on current page only

glenwglenw Posts: 3Questions: 1Answers: 0

There may well be a better way of achieving what I want but i have a datatable and i want to check if any setting have changed periodicaly. If so i want to append a class to a button on the datatable.
I can use

var table = $('#joblist').DataTable();
table.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
var id =this.id();

.......
get value using id and if different append class
.......

});

This works fine and displays as expected on the current page but if there is pagination and you change page the changes have not happened?

I can make the code run again if the user clicks on a different page but would mean making unnecessary calls to the server as the loop is going through the full datatable and not just the current page.

So is there a way of either.
making sure the changes are applied to all pages
or
can I alter the loop so that it only loops through the current page and not the whole datatable.

Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 62,217Questions: 1Answers: 10,206 Site admin
    Answer ✓

    Use the selector-modifier options which you can pass into the DataTables selector methods (i.e. rows() in this case). For example: table.rows( { page: 'current' } ).every( ... );

    Another option might be createdRow, but it depends upon how you are using DataTables. I'd really need a test case or a debug trace to understand how it is configured.

    Allan

  • glenwglenw Posts: 3Questions: 1Answers: 0

    Thanks Allan
    I've ended up just getting the table rows and manipulated the cells through jquery which seems to be working well.
    I don't really read instruction much and tend to learn from examples and trial and error.
    Can you tell me is there a list of modifier types like 'page: current' as I'm sure I will be able to make use of these in the future.
    Thanks again

  • glenwglenw Posts: 3Questions: 1Answers: 0

    Also Allan would you know if there is a way to run the function when a user types in the search box and if they change the number of records to be displayed?

    Thanks

  • allanallan Posts: 62,217Questions: 1Answers: 10,206 Site admin
    edited April 2016

    Can you tell me is there a list of modifier types like 'page: current' as I'm sure I will be able to make use of these in the future.

    Yes, in the selector-modifer documentation that I linked to above :-).

    if there is a way to run the function when a user types in the search box and if they change the number of records to be displayed?

    search and length (edit typo in event name).

    The full, searchable, reference documentation is available here.

    Allan

This discussion has been closed.