Applying a change to all pages

Applying a change to all pages

trongarttrongart Posts: 222Questions: 51Answers: 0

This test case has the button "Change Color" which changes the text color of column 0 to red. For some reason, this change only applies to the first page. When switching pages, the color is not changed.

How can I apply the color change for .data0 to all pages?

https://live.datatables.net/pupihame/1/edit

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,993Questions: 87Answers: 421
    edited April 2023

    https://live.datatables.net/hebaxise/1/

    Use the api and it works. Your way would only work for the rows currently visible.

    table.column(0).nodes().to$().css('color', 'red');
    

    and

    table.column(0).nodes().to$().css('color', '');
    
  • trongarttrongart Posts: 222Questions: 51Answers: 0
    edited April 2023

    Thank you very much! However, this does not work when using "deferRender": true as here: https://live.datatables.net/jeqifeso/1/edit

    Is there a way to apply the change when "deferRender": true ?

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    That is true and is documented in the deferRender docs:

    Note that when enabled, it goes without saying that not all nodes will always be available in the table, so when working with API methods such as columns().nodes() you must take this into account

    In this case use rowCallback to apply or remove the color based on the clicked button. Use a global variable as a flag to track which button is clicked. For example:
    https://live.datatables.net/raxugoke/1/edit

    Kevin

Sign In or Register to comment.