st-pagination
Can you add Go-To-Last, Go-To-First buttons? Or can you tell me how I can control the pagination?
you can modify the pagination template either in the $templateCache when you config your application or set the st-template attribute to the pagination directive (the value should be the template url you want)
In this template you can add buttons
<a ng-click="selectPage(1)">got to first</a> <a ng-click="selectPage(numPages)">go to last</a>
Thank you I was able to replace the template,
@ivanbaj could you post some sample code? I have the same requirement
The default template for pagination is almost perfect, why not adding the First and Last buttons through an option? That would be awesome.
Could give examples on to implement some of these:
http://netdna.webdesignerdepot.com/uploads/2009/02/pagination.png
I agree with @tigroumeow. The first and last buttons are important for pagination. I think almost everyone needs it and should be added into the default template.
There is pagination template sample: /components/search/pagination.html
<div class="pagination" ng-if="pages.length >= 2">
<ul class="pagination">
<li>
<a ng-click="selectPage(1)" aria-label="First">
<span aria-hidden="true">first</span>
</a>
</li>
<li>
<a ng-click="selectPage(currentPage-1)" aria-label="Previous">
<span aria-hidden="true">←</span>
</a>
</li>
<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a ng-click="selectPage(page)">{{page}}</a></li>
<li>
<a ng-click="selectPage(currentPage+1)" aria-label="Next">
<span aria-hidden="true">→</span>
</a>
</li>
<li>
<a href="" ng-click="selectPage(numPages)" aria-label="Last">
<span aria-hidden="true">last</span>
</a>
</li>
</ul>
</div>
And usage sample:
<td class="text-center" st-pagination="" st-items-by-page="15" st-template="/components/search/pagination.html" colspan="5">
+1, first and last buttons should come by default
I had the same requirement. Template provided by jroom36 works perfectly
Thank you jroom36 for a nice solution
lorenzofox3 and jroom36 good work... nice solution...
Yup the API isn't well too documented on this capability maybe I am just not finding the page on this. All I found was an example of custom pagination right at the bottom of the page. Though from what I gathered, I was able to make a relatively complex version of the pagination template that adds the following features
- No first and last buttons (instead the first and last page numbers are shown on screen)
- Ellipses between the first page and the set and last page and the set conditionally shown when needed. Clicking on them shifts you to the next page of pages.
- Previous and next page buttons are disabled on first and last page respectively.
<ul class="pagination">
<li ng-class="{disabled: currentPage == 1}">
<a ng-click="selectPage(currentPage-1)" aria-label="Previous">
<span aria-hidden="true"><i class="fa fa-angle-left"></i></span>
</a>
</li>
<li ng-show="pages.indexOf(1) == -1"><a
ng-click="selectPage(1)">1</a>
</li>
<li ng-show="pages.indexOf(2) == -1"><a
ng-click="selectPage(pages[0])">...</a>
</li>
<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a
ng-click="selectPage(page)">{{page}}</a>
</li>
<li ng-show="pages.indexOf(numPages -1) == -1"><a
ng-click="selectPage(pages[pages.length - 1])">...</a>
</li>
<li ng-show="pages.indexOf(numPages) == -1"><a
ng-click="selectPage(numPages)">{{numPages}}</a>
</li>
<li ng-class="{disabled: currentPage == numPages}">
<a ng-click="selectPage(currentPage+1)" aria-label="Next">
<span aria-hidden="true"><i class="fa fa-angle-right"></i></span>
</a>
</li>
</ul>
Here's how to globally configure the template without messing with $templateCache. Probably not the safest way, as it's not advertised in the API.
Smart Table has a constant called 'stConfig'
I made use of this constant to configure (similar to other libraries global config) the default template.
app.config(function(stConfig) {
stConfig.pagination.template = 'pagination.custom.html';
});
Agreed. Ergonomics of default pagination is terrible ! we can't go to the first/last page, and we can't know the number of page.
@trajano I can't get your template to work... The pagination looks like this: https://cl.ly/302h3x1n0W0x Do the "pages" need to be on the $scope in my controller?
Nvm, I got it :-)
@mrn-aglic sorry it's been over a year ago since I touched AngularJS I already switched to Vue. However, it looks like it needs to be in the same scope as you have selectPage wherever that is.
@trajano no prob, I found the issue... I was setting st-displayed-pages to display all pages. Setting it to a small number, e.g. 7 gives what I expected. (except for the prev and next buttons, still have to see why the arrows aren't displayed). But thank you for your quick response
Has anyone implemented delete functionality as well using smart table. In my case if I delete any item, the page goes back to the first page, as there is a change in the collection to which smart table is bound.
I was expecting the page should remain unchanged. eg : If deleting an item from second page with total 7 items, and 4 items /page. It should still remain on second page.
Yet another template based on alexey-yurganov's version .
- First & Last buttons
- Jump forward/backward stDisplayedPages. This achieves more efficient short range scrolling.
Not sure why would anyone want to waste 2 buttons on forward and back by one page if the same can be achieved by simply clicking on the next/previous page number.
<div class="pagination" ng-if="pages.length >= 2">
<ul class="pagination">
<li>
<a ng-show="currentPage > stDisplayedPages/2" ng-click="selectPage(1)" aria-label="First"><span aria-hidden="true"><<</span></a>
</li>
<li>
<a ng-show="currentPage > stDisplayedPages" ng-click="selectPage(currentPage - stDisplayedPages)" aria-label="Previous Page"><span aria-hidden="true"><</span></a>
</li>
<li ng-repeat="page in pages" ng-class="{active: page == currentPage}">
<a ng-click="selectPage(page)">{{page}}</a>
</li>
<li>
<a ng-show="currentPage < numPages - stDisplayedPages" ng-click="selectPage(currentPage + stDisplayedPages)" aria-label="Next Page"><span aria-hidden="true">></span></a>
</li>
<li>
<a ng-show="currentPage < numPages - stDisplayedPages/2" ng-click="selectPage(numPages)" aria-label="Last"><span aria-hidden="true">>></span></a>
</li>
</ul>
</div>