How do I access a checkbox on non-visible rows?

How do I access a checkbox on non-visible rows?

paul.allsopppaul.allsopp Posts: 3Questions: 1Answers: 0

I cannot provide a test-case as this is a private codebase, but I think the question is quite simple: I have a table with about 20k rows, which are in groups by some data attribute on the table row. I have a "Select all group or none" type button, but when I press it only the first 64 checkboxes in a group are checked. I tested getting a count of all the rows with a certain data attribute but only get 64 unless I scroll the table when the count goes up to about 116 and then goes down again. I assume this is a memory/performance restraint.

This table is not tied to any web-based service, so all 20k rows load. Thus the underlying table exists in full.

Can I do a select on only the rows in question that will return all rows with said data attribute?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948
    edited September 2023 Answer ✓

    The answer is it depends :smile: If you are using standard jQuery or Javascript methods to access the checkboxes then they will only retrieve the rows in the document. These will be the rows displayed on the page. Datatables removes the other rows from the document until they are needed to be displayed.

    Are you using the Scroller extension?

    Are you using server side processing, ie have serverSide: true? This will affect the rows you have access to as only the rows displayed are at the client. You will need a server based function to check and uncheck all the checkboxes.

    One option is to use cells().nodes(), column().nodes() or rows().nodes() to have access to all the rows. This example show one way to get all the checked checkboxes and to toggle a Select All checkbox. These options will not work with server side processing.
    https://live.datatables.net/mutavegi/5/edit

    If this doesn't help then please build a simple example that shows your checkboxes and how you are currently selecting all. This way we can see what you have to offer more specific suggestions.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • paul.allsopppaul.allsopp Posts: 3Questions: 1Answers: 0

    Thank you, Kevin. I'll give that a go.

  • paul.allsopppaul.allsopp Posts: 3Questions: 1Answers: 0

    $('#crMarkupTable').DataTable().rows('tr.material-group-10001').nodes().length

    Happy camper! Thanks again!

Sign In or Register to comment.