I'm working with bootstrap table and ngStorage. What I'm trying to do is to save search to local storage and retrieve it back after table has been refreshed. This is my simple code:
js
//Assigning $localstorage to $session.storage
$scope.storage = $localStorage;
$scope.saveSearch = function () {
$scope.child = prompt('Set your filter.');
$('#table').on('search.bs.table', function (e, text){
$scope.storage = text
});
};
$scope.loadSearch = function() {
$scope.data = $scope.storage;
};
html
<div id="toolbar">
<div style="display: -webkit-box">
<button id="new" class="btn btn-default">New</button>
<button id="edit" class="btn btn-default">Edit</button>
<button id="remove" class="btn btn-default">Delete</button>
<button class="btn btn-default " ng-click="saveSearch()">Save Filter</button>
<button class="btn btn-default " ng-click = "loadSearch()">Load Filter</button>
<button id="button" class="btn-primary btn">Load Table</button>
<pre>{{data}}</pre></div>
</div>
table id="table"
class="table-striped"
data-toggle="table"
data-toolbar="#toolbar"
data-search="true"
data-show-columns="true"
data-show-export="true"
data-filter-control="true"
data-events="operateEvents"
data-formatter="operateFormatter"
data-response-handler="responseHandler"
>
</table>
and thru this code I'm getting variable back, when I click on button Load Filter. You can see that on the right side of Load Table button.
But when I'm trying to push this variable to search.
$scope.loadSearch = function() {
$('#table').on('search.bs.table', function (e, text){
text.push($scope.storage);
console.log($scope.storage)
});
$scope.data = $scope.storage;
};
My function doesn't work at all. I appreciate if anybody could explain me where is my mistake?
My plunker, where you can see the problem
With this plunker, you can put value from localstorage to search bs table, but it is not triggering.
To save text to local storage
$scope.storage.text = text;
and than to retrieve the text
$scope.data = $scope.storage.text