lorenzofox3 / Smart-Table

Code source of Smart Table module: a table/grid for Angularjs
http://lorenzofox3.github.io/smart-table-website/
1.8k stars 513 forks source link

Add Scroll to Top in Pagination #829

Closed ghost closed 6 years ago

ghost commented 6 years ago

Add: $location + $anchorScroll to allow scroll to top.

//view -> table state scope.selectPage = function (page) { if (page > 0 && page <= scope.numPages) { ctrl.slice((page - 1) * scope.stItemsByPage, scope.stItemsByPage); } $location.hash('top'); $anchorScroll(); }; if (!ctrl.tableState().pagination.number) { ctrl.slice(0, scope.stItemsByPage); $location.hash('top'); $anchorScroll(); }

Remember to add services to the Directive:

.directive('stPagination', ['stConfig', '$location', '$anchorScroll', function (stConfig, $location, $anchorScroll) {

Then in your template add: id="top"

824

MrWook commented 6 years ago

Hello @paul-rogers-dev,

how about you recreate the pull request without all the commits since 2013. There should be only your own commit.

But anyway i think that this feature is missing too but i don't think that $anchor is the correct approach for this. First off, this will force me to use a unique id for the body but what if i have several tables? I can tell you that i really got several on one site. Second off, "top" is a really generic name which will likely to be on the site for other stuff.

I tried to solve this problem with a decorator for the pagination directive where i overwrite the selectPage function. There I get the body and scroll it to the top with plain old JavaScript element.scrollTop = 0. But the problem here is that the pagination will be put on different locations so this is also a !NO GO! for the Master SmartTable Branch