Add Checkbox to datatables

Add Checkbox to datatables

johngtrsjohngtrs Posts: 33Questions: 2Answers: 0
edited August 2015 in Free community support

Hi,

I'm server side I want to add a checkbox who returns true or false when the checkbox is checked or not. But I don't know how to add the event on change to my checkbox in the table and send the boolean to my data. And I want to set the checkbox next to the global search.

//--- JQUERY ---
$(document).ready(function() {
      $('#searchlog').DataTable({
              serverSide: true,
              aaSorting: [[1, 'desc']],
              ajax: {
                  url: '/mypath/...',
                  method: 'POST',
                  data: {
                        caseSensitive: true // I want the checkbox's return on this parameter
                    }
              }
       });
            $('#idCaseSensitive').change(function(data) {
              if(this.checked) {
                return true;
              }else{
                return false;
              }
            });
});

//--- HTML ---
<table id="searchlog" class="table table-striped table-bordered" cellspacing="0" width="100%">

  Case Sensitive : <input type='checkbox' id='idCaseInsensitive' />

  <thead> 
    <tr>
      <th>COL1</th>
      <th>COL2</th>
      <th>COL3</th>
      <th>COL4</th>
      <th>COL5</th>
      <th>COL6</th>
      <th>COL7</th>
      <th>COL8</th>
    </tr>

  </thead>

  <tbody>  
    </tbody>
</table>

Could you help me to do that please?

Thanks in advance.

Answers

  • johngtrsjohngtrs Posts: 33Questions: 2Answers: 0

    Up please.

  • johngtrsjohngtrs Posts: 33Questions: 2Answers: 0

    How can I add a method to my datatable variable before .draw() ?

            var tableCase = $('#searchlog').DataTable();
             
            $('#idCaseSensitive').change(function () {
                
                if (this.checked) {
                    flag=true;
                } else {
                    flag=false;
                }
                tableCase    // Here how can I add .caseSensitive() for example ?
                         .draw(); 
            } );
    
  • johngtrsjohngtrs Posts: 33Questions: 2Answers: 0

    I solved my issue with a function who returns the flag variable and I use it in the data caseSensitive.

This discussion has been closed.