Datatable 1.10 erase data when filtering

0

I am inserting data in a table with datatable, at the time of using the filter it filters, but it deletes the data that was already loaded in the table.

<div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-2" data-widget-editbutton="false">

                <header>
                  <span class="widget-icon"> <i class="fa fa-table"></i> </span>


                </header>

                <!-- widget div-->
                <div>

                  <!-- widget edit box -->
                  <div class="jarviswidget-editbox">
                    <!-- This area used as dropdown edit box -->

                  </div>
                  <!-- end widget edit box -->

                  <!-- widget content -->
                  <div class="widget-body no-padding">

                    <table id="tabla" class="table table-striped table-bordered table-hove tabla_ot" width="100%">
                      <thead>
                        <tr>
                          <th>Dato1</th>
                          <th>Dato2</th>
                          <th>Dato3</th>
                          <th>Dato4</th>
                          <th>Dato5</th>
                          <th>Dato6</th>
                          <th>Dato7</th>
                          <th>Dato8</th>
                          <th>Dato9</th>
                          <th>Dato10</th>
                          <th>Dato11</th>
                          <th>Dato11</th>
                        </tr>
                      </thead>
                      <tbody>
                       <!-- los datos se cargan aca , pero al usar el filtro de datatable se borran-->
                      </tbody>
                    </table>

                  </div>
                  <!-- end widget content -->

                </div>
                <!-- end widget div -->

              </div>
<!-- agrego el filtro y el paginado-->
$( document ).ready(function() {
   $('#tabla').DataTable( {
    scrollY: 300,
    paging: true
} );


 <!-- inserto los datos al tbody con jquery-->
 $.each(obj.lista, function (ind, elem) { 

    $('#tabla > tbody').html('<tr id="token()" class="row_ot" onclick="Redirec('+elem.valor1+')"><td>'+elem.valor2+'</td><td>'+elem.valor3+'</td><td>'+elem.valor4+'</td><td>'+elem.valor5+'</td><td>'+elem.valor6+'</td><td>'+elem.valor7+'</td><td>'+elem.valor8+'</td><td>'+elem.valor9+'</td><td>'+elem.valor10+'</td><td>'+elem.valor11+'</td><td>'+elem.valor12+'</td><td>'+elem.valor13+'</td></tr>');     
    });

The data is loaded at the beginning of the search even if it finds a match, it deletes the data of tbody , it occurs to me that maybe there is a datable function that cancels this behavior

    
asked by Javier Antonio Aguayo Aguilar 31.05.2017 в 19:39
source

1 answer

0

DataTables internally stores the data for your purposes.

I recommend you do this before editing the table, adding rows the way you do.

 $('#tabla').DataTable().clear().destroy();

What causes the content of your table to be deleted and DataTable to remove all internal data it has on your table.

Then you insert the new tr with your loop, and then reinitialize DataTable


 $('#tabla').DataTable({
    scrollY: 300,
    paging: true
}); 

This solves your problem.

    
answered by 21.10.2017 в 16:03