Selecting All Rows and table.on('draw')

Selecting All Rows and table.on('draw')

trongarttrongart Posts: 222Questions: 51Answers: 0
edited April 2023 in Free community support

This test case includes a simulated large table with 80000 results: https://live.datatables.net/qejufuqi/1/edit

There is a button Select All Rows that selects both the main rows and the subrows.

table.on('draw') function makes sure that subrows are still selected when changing pages as without this function, only the main rows stay selected when switching pages.

table.on('click','tr',function(e)) function makes sure relevant subrows are selected when a main row is selected.

The problem is that table.on('draw') runs too slowly when there are so many results which is an issue when all rows are selected and the page changed.

What could be done to improve performance of table.on('draw') or is there maybe another approach to this?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin
    Answer ✓

    No need to use Javascript to add a class to the child row. Use this CSS selector:

    tr.selected + tr {
      background-color: yellow !important;
    }
    

    That says, get any tr which is directly after a tr.selected element. Then you have no need for a draw event handler at all: https://live.datatables.net/celuwato/1/edit

    Allan

  • trongarttrongart Posts: 222Questions: 51Answers: 0

    Fantastic, thank you!

Sign In or Register to comment.