Restart or uncheck all the selected options in datatable plugin "checkboxes"

1

I am using an extension for the jQuery DataTables library that serves to select multiple rows of the datatable and make operations with them. The extension is

  

jQuery DataTables Checkboxes

link

But I have a problem. I need that after performing an action on the selected records, all records are unchecked, but I can not do it.

I have tried to do nombreTabla.column(nColumnaDondeEstaElCheckbox).checkboxes.select(false) after doing the necessary operations but it does not respond. I have also tried to unmark all the input [type = checkbox] of the page but neither.

Any ideas about this "plugin-extension" of datatable?

    
asked by M. Giner 18.05.2018 в 07:11
source

1 answer

2

Use nombreTabla.columns().checkboxes.deselect(true) or nombreTabla.columns().checkboxes.deselectAll() .

I leave the link to the API

And here an example:

$(document).ready(function() {

  var dataSet = [
    ["Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011/04/25", "$320,800"],
    ["Garrett Winters", "Accountant", "Tokyo", "8422", "2011/07/25", "$170,750"],
    ["Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009/01/12", "$86,000"]
  ];

  var columnDefs = [{
    title: "Name"
  }, {
    title: "Position"
  }, {
    title: "Office"
  }, {
    title: "Extn."
  }, {
    title: "Start date"
  }, {
    title: "Salary"
  }];

  var myTable;

  myTable = $('#example').DataTable({
    "sPaginationType": "full_numbers",
    data: dataSet,
    'columnDefs': [
         {
            'targets': 0,
            'checkboxes': {
               'selectRow': true
            }
         }
      ],
      'select': {
         'style': 'multi'
      },
      'order': [[1, 'asc']],
    columns: columnDefs,
		dom: 'Bfrtip',        // Needs button container
          select: 'single',
          responsive: true,
          altEditor: true,     // Enable altEditor
          buttons: [{
            text: 'Add',
            name: 'add'        // do not change name
          },
          {
            extend: 'selected', // Bind to Selected row
            text: 'Edit',
            name: 'edit'        // do not change name
          },
          {
            extend: 'selected', // Bind to Selected row
            text: 'Delete',
            name: 'delete'      // do not change name
         }]
  });

$("#desactivar").on("click",function(){
//myTable.columns(0).checkboxes.deselect(true);
myTable.columns().checkboxes.deselectAll()
});


});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container">
<link href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css" rel="stylesheet"/>
<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.min.js"></script>
<link href="https://gyrocode.github.io/jquery-datatables-checkboxes/1.2.6/css/dataTables.checkboxes.css" rel="stylesheet"/>
<script src="https://gyrocode.github.io/jquery-datatables-checkboxes/1.2.6/js/dataTables.checkboxes.min.js"></script>

  <table cellpadding="0" cellspacing="0" border="0" class="dataTable table table-striped" id="example">

  </table>
  <input id="desactivar" type="button" value="Desactivar"/>
</div>
    
answered by 18.05.2018 / 08:49
source