简体   繁体   中英

How to show Total number of pages in YUI Paginator?

I am using YUI Paginator API for pagination and I need to show Total number of pages on screen. I saw that there is a function getTotalPages() in API but I am unsure about how to use it, there isn't enough documentation. Also after looking at some other documentation I tried using {totalPages} but didn't work. Can somebody help me out in this issue? Thanks in advance!! Below is the code snippet I am using. Please refer to template object from config:

config = {
                rowsPerPage: 100,

                template :
                    '<p class="klass">' +

                        '<label>Total pages: {totalPages}</label>'+
                        '<label>Page size: {RowsPerPageDropdown}</label>'+
                    '</p>',
                rowsPerPageDropdownClass : "yui-pg-rpp-options",
                rowsPerPageOptions  : [
                                   { value : 100 , text : "100" },
                                   { value : 250 , text : "250" },
                                   { value : 500 , text : "500" },
                                   { value : 1000 , text : "1000" },
                                   { value : tstMap[tabName].length , text : "All" }
                                ],
            };                                                            
 var myPaginator = new YAHOO.widget.Paginator(config);

The Paginator utility allows you to display an item or a group of items depending on the number of items you wish to display at one time.

Paginator's primary functionality is contained in paginator-core and is mixed into paginator to allow paginator to have extra functionality added to it while leaving the core functionality untouched. This allows paginator-core to remain available for use later on or used in isolation if it is the only piece you need.

Due to the vast number of interfaces a paginator could possibly consist of, Paginator does not contain any ready to use UIs. However, Paginator is ready to be used in any Based-based, module such as a Widget, by extending your desired class and mixing in Paginator. This is displayed in the following example:

 YUI().use('paginator-url', 'widget', function (Y){
            var MyPaginator = Y.Base.create('my-paginator', Y.Widget, [Y.Paginator], {

               renderUI: function () {
                   var numbers = '',
                       i, numberOfPages = this.get('totalPages');

                   for (i = 1; i <= numberOfPages; i++) {
                       // use paginator-url's formatUrl method
                       numbers += '<a href="' + this.formatUrl(i) + '">' + i + '</a>';
                   }

                   this.get('boundingBox').append(numbers);
               },

               bindUI: function () {
                   this.get('boundingBox').delegate('click', function (e) {
                       // let's not go to the page, just update internally
                       e.preventDefault();
                       this.set('page', parseInt(e.currentTarget.getContent(), 10));
                   }, 'a', this);

                   this.after('pageChange', function (e) {
                       // mark the link selected when it's the page being displayed
                       var bb = this.get('boundingBox'),
                           activeClass = 'selected';

                       bb.all('a').removeClass(activeClass).item(e.newVal).addClass(activeClass);
                   });
               }

            });

            var myPg = new MyPaginator({
                           totalItems: 100,
                           pageUrl: '?pg={page}'
                       });

            myPg.render();
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM