Smart-Table icon indicating copy to clipboard operation
Smart-Table copied to clipboard

st-pagination

Open ghost opened this issue 12 years ago • 19 comments

Can you add Go-To-Last, Go-To-First buttons? Or can you tell me how I can control the pagination?

ghost avatar Nov 18 '14 19:11 ghost

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>

lorenzofox3 avatar Nov 19 '14 03:11 lorenzofox3

Thank you I was able to replace the template,

ghost avatar Nov 21 '14 03:11 ghost

@ivanbaj could you post some sample code? I have the same requirement

mirko77 avatar Dec 01 '14 12:12 mirko77

The default template for pagination is almost perfect, why not adding the First and Last buttons through an option? That would be awesome.

jordymeow avatar Jan 22 '15 03:01 jordymeow

Could give examples on to implement some of these:

http://netdna.webdesignerdepot.com/uploads/2009/02/pagination.png

jeffhoang avatar Mar 11 '15 17:03 jeffhoang

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.

lvarayut avatar Jun 14 '15 05:06 lvarayut

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">&larr;</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">&rarr;</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">

alexey-yurganov avatar Jul 02 '15 09:07 alexey-yurganov

+1, first and last buttons should come by default

mirko77 avatar Jul 02 '15 10:07 mirko77

I had the same requirement. Template provided by jroom36 works perfectly

bjspatel avatar Oct 30 '15 10:10 bjspatel

Thank you jroom36 for a nice solution

chris-wood-dynmark avatar Oct 30 '15 13:10 chris-wood-dynmark

lorenzofox3 and jroom36 good work... nice solution...

elangesk avatar Mar 08 '16 20:03 elangesk

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>

trajano avatar Mar 14 '16 02:03 trajano

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';  
});

pedro-mass avatar Mar 31 '16 16:03 pedro-mass

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.

amdev74 avatar Nov 09 '16 10:11 amdev74

@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 avatar Nov 16 '17 12:11 mrn-aglic

@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 avatar Nov 16 '17 12:11 trajano

@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

mrn-aglic avatar Nov 16 '17 12:11 mrn-aglic

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.

ROHITSING avatar Nov 30 '17 10:11 ROHITSING

Yet another template based on alexey-yurganov's version .

  1. First & Last buttons
  2. 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>

Zarium avatar May 01 '19 20:05 Zarium