How to change the datatable property of a created table

0

I want to change the serverSide property to false if the condition is satisfied, how to change this from a table created with Datatable?

    var tabela = $("#lista-dados").DataTable({
      "processing": false,
      "serverSide": true,
      "autoWidth": true,
      "ajax": {
        "type": "POST",
        "data": ws_datatable,
        "url": "./functions/ws_datatable.php"
      },
      "lengthMenu": [[10, 25, 50, 100, 250, 500, -1]],
      "pageLength": 10,
      "bStateSave": true,
      "paging": true,                                    
      "dom": "lBfrtipr",

   });

It would be something I wanted to do

if (x == 2) {
 "serverSide": false,
}
    
asked by anonymous 19.07.2018 / 19:42

1 answer

0

DataTables has a number of settings that can only be set at boot time not later.

See link for more details

Proposed solution

To change this option destroys the DataTable and rebuilds

Initialization

 var tabela = $("#lista-dados").DataTable({
      "processing": false,
      "serverSide": true,
      "autoWidth": true,
      "ajax": {
        "type": "POST",
        "data": ws_datatable,
        "url": "./functions/ws_datatable.php"
      },
      "lengthMenu": [[10, 25, 50, 100, 250, 500, -1]],
      "pageLength": 10,
      "bStateSave": true,
      "paging": true,                                    
      "dom": "lBfrtipr",

   });

Change

if (x == 2) {



 if ( $.fn.dataTable.isDataTable( '#lista-dados' ) ) {

      table = $('#example').DataTable();
      table.destroy();


     var tabela = $("#lista-dados").DataTable({
          "processing": false,
          "serverSide": false, 
          "autoWidth": true,
          "ajax": {
            "type": "POST",
            "data": ws_datatable,
            "url": "./functions/ws_datatable.php"
          },
          "lengthMenu": [[10, 25, 50, 100, 250, 500, -1]],
          "pageLength": 10,
          "bStateSave": true,
          "paging": true,                                    
          "dom": "lBfrtipr",

       });


}


}
    
19.07.2018 / 21:29