Skip to content
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

Dynamically setting max number of rows #34

Open
ghost opened this issue May 16, 2013 · 0 comments
Open

Dynamically setting max number of rows #34

ghost opened this issue May 16, 2013 · 0 comments

Comments

@ghost
Copy link

ghost commented May 16, 2013

Gabriel,

We need to dynamically set the number of rows to be paginated as we perform an iterative search through our dataset. As far as I can see, the plugin only allows this to be set at creation.So I have created a new binding, thus -

    containers.bind('setNumRows', {numPages:np}, function(evt, numRows) {
            var current_page = $(this).data('current_page');        
            console.warn("jquery.paginate : setNumRows " + numRows + " " + current_page) ;
            // Create a sane value for maxentries from the supplied number of rows
            numRows = (!numRows || numRows < 0)?1:numRows;
            if (numRows != maxentries)
            {
                maxentries = numRows ;
                // calculate how many pages we now need
                var newMaxPage = Math.ceil(maxentries/opts.items_per_page);
                console.warn("jquery.paginate : setNumRows updating number of pages to " + newMaxPage) ;
                // check if the current page is not within the new current set of pages
                if (current_page > newMaxPage)
                    current_page = newMaxPage ;
                renderer = new $.PaginationRenderers[opts.renderer](maxentries, opts);
                links = renderer.getLinks(current_page, paginationClickHandler);
                containers.empty();
                if(newMaxPage > 1 || opts.show_if_single_page) {
                    links.appendTo(containers);
                }
            }
            return false;
    });

(sorry about leaving in the console.warn debugging).

Is this appropriate for inclusion in your excellent plugin?

Kind regards
Chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants