statesave not working with datatables when rows are added dynamically

3.9k Views Asked by At

I am using DataTables and I initialize the table with

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

I populate my table dynamically using $('#example').row.add(...)

When I reload or revisit my page, the table is empty again. Is stateSave supposed to work with dynamically inserted row entires?

3

There are 3 best solutions below

0
Webezine On

State save isn't used to save data - only pagination etc..

1
MrMadsen On

Try changing stateSave to bStateSave. Worked for me when my code had this same issue.
So the code would be something like:

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

Be sure that you have localstorage enabled! Encoutnered this myself and it wasn't enabled which caused the issue.