4

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?

user3871397
  • 81
  • 1
  • 2
  • what browser are you seeing this in? – morissette Oct 15 '14 at 02:48
  • chrome. but a table with pre-populated entires is working (that is, datatables remembers my sorting) – user3871397 Oct 15 '14 at 03:23
  • State is not data. `State.save()` does not save the content of the table, only such as pagination position, display length, filtering, sorting. See -> https://datatables.net/reference/option/stateSave – davidkonrad Oct 15 '14 at 07:16

3 Answers3

2

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
    } );
} );
MrMadsen
  • 2,713
  • 3
  • 22
  • 31
1

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

Webezine
  • 345
  • 7
  • 22
0

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