angular-datatables
angular-datatables copied to clipboard
How to properly set and clear stateSave?
stateSave is pretty useful for persisting table state for a serverSide based table.
I have instances where I'd like to datatable's state to be saved (update some row data) and others where I don't (reset button).
$scope.updateData = function (saveState) {
$scope.dtOptions.stateSave = saveState;
$scope.dtInstance.rerender();
}
This above code works immediately when I call it with false, but requires me to call it twice with true before it saves again. How do I properly set the value for stateSave?
I found a solution.
Always initialize stateSave to true, then use this code:
$scope.updateData = function (saveState) {
if (!saveState) { // clear state unless told to save
$scope.dtInstance.DataTable.state.clear();
}
$scope.dtInstance.rerender();
};