daniel-nagy / md-data-table

Material Design Data Table for Angular Material
MIT License
1.9k stars 519 forks source link

Save the sorting/filtering/grouping/paging state #537

Open josoroma-zz opened 7 years ago

josoroma-zz commented 7 years ago

Hi Hackers!

Is there a built-in mechanism to save the state of the grid we are working on and then at a later time when we come back to that page the state would be the same?

If not, is cookies or localStorage the recommended way to go?

Thanks in advance fellas!

kybarg commented 7 years ago

Here you are: Extend default query with params from url angular.extend(vm.query, $location.search()); and change url after query change $location.path($location.path()).search(vm.query);

zhenya2224 commented 7 years ago

Kybarg, thanks for your response, can you please provide more details. If for example I have control which allows me to change displayed columns, how can I save this settings?

Also Extend default query with params from url angular.extend(vm.query, $location.search()); and change url after query change $location.path($location.path()).search(vm.query);

This should be done in controller?

kybarg commented 7 years ago

@zhenya2224 Yes, you need to adjust your controller. Look at example here https://github.com/daniel-nagy/md-data-table/blob/gh-pages/scripts/nutritionController.js It will be $scope.query in that particular case btw. And $location.path($location.path()).search($scope.query); should be executed after getting data.

zhenya2224 commented 7 years ago

Kybarg, thanks again for your response, I will try this tomorrow. And one more thing, if I want to save the sorting setting (for example I click on the table header column - sort by name) and I want to keep that sorting setting when I leave the page, also $scope.query logic applies?

kybarg commented 7 years ago

@zhenya2224 sure. It set $scope.query params by default.

zhenya2224 commented 7 years ago

Kybarg, many thanks, its working)