angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

How to properly set and clear stateSave?

Open vinays84 opened this issue 10 years ago • 1 comments

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?

vinays84 avatar Aug 08 '16 23:08 vinays84

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();
};

vinays84 avatar Aug 22 '16 18:08 vinays84