How do I select all non-rendered checkboxes?

How do I select all non-rendered checkboxes?

MethodDevMethodDev Posts: 3Questions: 2Answers: 0
edited October 2016 in Free community support

I have a datatable which is generated but I cannot get the non-rendered checkboxes to check.

My table is called "myTable" ( nail on the head there! ) but I cannot get the fnHiddenNodes to work :(

Here is the code I am trying:

1. 
2.   <script type="text/javascript">
3.         var table = "";
4.         var allPages = "";
5.         $(document).ready(function ()
6. 
7.  {
8.             table = $('#myTable').DataTable({
9.                 "dom": '<"top"fl>rt<"bottom"pi><"clear">',
10.                 stateSave: true
11.                 
12.                     /*'<"top"lf>rt<"bottom"p><"clear">'*/
13. 
14.             });
15.             allPages = table.fnGetNodes();
16. 
17.     } );
18.         
19.         function selectAllAttys() {
20. 
21. 
22.             $(':checkbox').each(function () {
23.                 this.checked = true;
24.             });
25. 
26.             $('input[type="checkbox"]', allPages).prop('checked', true);
27. 
28.         }
29. 
30.         </script>

Answers

  • MethodDevMethodDev Posts: 3Questions: 2Answers: 0

    Found solution:
    https://datatables.net/plug-ins/api/fnGetHiddenNodes

    Please close topic.

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin

    fnHiddenNodes is legacy. Indeed so is fnGetNodes (using the code you have above, it will either be throwing an error, or you must be using DataTables 1.9 or earlier).

    With 1.10 you would use:

    $('input[type="checkbox"]', myTable.rows().nodes() ).prop('checked', true);
    

    or:

    myTable.rows().nodes().to$().find( 'input[type="checkbox"]' ).prop('checked', true);
    

    Allan

This discussion has been closed.