Datatables - jquery-datatables-checkboxes (gyrocode.com) checkboxes question

Datatables - jquery-datatables-checkboxes (gyrocode.com) checkboxes question

dinos_1974dinos_1974 Posts: 2Questions: 1Answers: 0

Many thanks for reading.
This is for an open source project I created for a K12 school.
Please see the following:

http://users.sch.gr/chertour/projectsms/sms_list_ajax_demo.html

You will find:

  1. Serverside Data fetched and embedded into a Datatable
  2. The www.gyrocode.com plugin for enabling checkboxes ( jQuery DataTables Checkboxes )

I have enabled the first row as the checkboxes row.
When I click in a checkbox the rowID is printed in a <span> element.
Multiple checkboxes printed as expected.
When I press the Selectall checkbox the checkboxes are all selected but nothing is printed.
When I toggle (selectall checkbox UNSELECTED) then every value is printed.
It is supposed to be the other way around. Code is based on the tutorials and the examples.
I have tried numerous variations but to no avail.
Is there something I miss?
Any ideas or suggestions greatly appreciated.

Answers

  • dinos_1974dinos_1974 Posts: 2Questions: 1Answers: 0

    For anyone interested the solution was given by the plugin author (www.gyrocode.com)

    Please see below:

    $(document).ready(function() {
       var table = $('#example').DataTable({
          'ajax': 'https://api.myjson.com/bins/1us28',
          'columnDefs': [
             {
                'targets': 0,
                'checkboxes': {
                   'selectRow': true,
                   'selectCallback': function(){
                      printSelectedRows();
                   }
                }
             }
          ],
          'select': {
             'style': 'multi'
          },
          'order': [[1, 'asc']]
       });   
    });
    
    // Print selected rows
    function printSelectedRows(){
       var rows_selected = $('#example').DataTable().column(0).checkboxes.selected();
    
       // Output form data to a console     
       $('#example-console-rows').text(rows_selected.join(","));
    };
    
This discussion has been closed.