Statesas does not work with datatables when rows are added dynamically

I am using DataTables and I am initializing the table with

$(document).ready(function() {
    $('#example').dataTable( {
        stateSave: true
    } );
} );

      

I am dynamically populating a table using $ ('# example'). row.add (...)

When I reload or revise my page, the table is empty again. Should StateSave work with dynamically inserted row?

+3


source to share


3 answers


State persistence is not used to persist data - only pagination, etc.



+1


source


Try changing stateSave to bStateSave. Worked for me when my code had this same problem.
Thus, the code will look something like this:



$(document).ready(function() {
    $('#example').dataTable( {
        bStateSave: true
    } );
} );

      

+1


source


Make sure you have local storage enabled! Found this myself and it was not enabled which caused the problem.

0


source







All Articles