-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore the state of a SmartTable - filters and page #825
Comments
Thank you, MrWook, for the precious suggestion.
I have the following directive that filters the table for min-max update date:
|
I observed that the pagination is gone when I refresh the page because the The filter/search keyword is perserved, but the pagination is gone.
|
Hello @SerhioV, i don't know what you are doing wrong, but in the example it will also save the pagination. If i should help you more i suggest that you create a plunk with your problem. |
Hello @SerhioV, this took me a while to figure out the problem..... For async data it will work when you delete And last but not least there is a lot of thing that you can improve in your code. You are mixing Angular coding styles. When you use the "Ctrl AS tc" stop using the $scope inside the controller and only use the object notation within the html. But the most important thing is try not to use ngInit. It's even written in the angular documentation. The things you want to "init" aren't necessary for it. You can just define it inside the controller. |
Hello @MrWook and thanks for trying to help ! ) I use I commented in the plunk the I observed that the problem is that the |
Hello @SerhioV, if you want to refere to the documentation with
This is something like this with PHP: So it is literally injecting some data from php into the HTML inside the ng-init. But if you can use $http requests you don't need ng-init. This can be done in the controller. Like i said your code triggers the pipe() function 6 times it should only trigger it once. the are reseting the pagination at some point. |
Then i didn't said anything sry. Did you initialized the variables for the table, displayed and tc.table.records ? |
I did't meant the controller. Are those two variables |
in the plunk I provided tc.table.records where not initialized as an empty array. I added this but this didn't fix the problelm. |
I even changed the $scope usage, you said do not mix, I changed like this and then changed
but all that didn't help to keep the current page to be reloaded correctly. I am on the plunker chat, if needed ;) |
Okey but still your table triggeres the pipe function 6 time and that will overwrite the tablestate. If you fix that it should work. I can't debug your whole code that is something that you need to do on your own. After all SmartTable is working like it should be. |
The solution I came up with. It works for me haha. I've added So i've decided to put the the intial storage state loader into a method called
|
For anyone running into this issue, the start page is set to 0 when something is changed, if you do some async loading in your controller, it will always set to 0 I changed $scope.$watch(function() {
var safeSrc = safeGetter($scope);
return safeSrc ? safeSrc.length : 0;
}, function(newValue, oldValue) {
if (newValue !== safeCopy.length) {
updateSafeCopy();
}
});
$scope.$watch(function() {
return safeGetter($scope);
}, function(newValue, oldValue) {
if (newValue !== oldValue) {
// tableState.pagination.start = 0;
updateSafeCopy();
}
}); It will prevent setting the page to 0 after an async update. |
AngularJs v 1.6.6; SmartTable v 2.1.8
I have items in row like
[id] [name] [edit]
.When the user edits an item(
/items/1/edit
), the item's EditPage contains a "back to list" link (/items
);That link returns the user to the list of the items. Now the problem is that in that case the page is always the first one, and any applied filters are lost.
Is there a way to say to the SmartTable to remember and restore the "before-edit mode" table state?
The text was updated successfully, but these errors were encountered: