Reputation: 2281
I've got a site using the jQuery Datatables plugin, which is mostly working very well.
However, for some reason its state saving code isn't being fired. Other options set at initialisation are being correctly picked up, but for some reason the state saving code isn't; there's no evidence of effect, cookie etc set, using either the straight initialisation parameter or specifically defining fnStateSave and fnStateLoad parameters (copying the code from the example at http://datatables.net/blog/localStorage_for_state_saving). It's all otherwise completely standard, data starting in the DOM, for the purposes of testing no other parameter set.
Is there a non-obvious setting I should make or limitation I should know about?
Upvotes: 3
Views: 5982
Reputation: 18813
To make this work you need DataTables 1.8 or higher...
bStateSave: true
Enable or disable state saving. When enabled a cookie will be used to save table display information such as pagination information, display length, filtering and sorting. As such when the end user reloads the page the display display will match what thy had previously set up.
Taken from DataTables Documentation
A full working example can be found here (debugging this example in Chrome showed both the fnStateSave
and fnStateLoad
being called.)
which does the following:
$(document).ready(function () {
$('#example').dataTable({
"bStateSave": true,
"fnStateSave": function (oSettings, oData) {
localStorage.setItem('DataTables_' + window.location.pathname, JSON.stringify(oData));
},
"fnStateLoad": function (oSettings) {
var data = localStorage.getItem('DataTables_' + window.location.pathname);
return JSON.parse(data);
}
});
});
Only using the following scripts:
<script type="text/javascript" language="javascript" src="jquery.js"></script>
<script type="text/javascript" language="javascript" src="jquery.dataTables.js"></script>
Upvotes: 7