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

Query String on Paging #149

Open
Bppatil opened this issue Jan 20, 2017 · 7 comments
Open

Query String on Paging #149

Bppatil opened this issue Jan 20, 2017 · 7 comments

Comments

@Bppatil
Copy link

Bppatil commented Jan 20, 2017

How to generate query string on page? i used this but not worked.
var obj = $('#pagination').twbsPagination({
totalPages: pagecount,
visiblePages: 4,
href:"search/product?page={{page}}"
});

Required result:

<a href="search/product?page=1" class="page-link">1</a> <a href="search/product?page=2" class="page-link">2</a> <a href="search/product?page=3" class="page-link">3</a>

Please help.

@eugenesimakin
Copy link
Collaborator

Hi!

First of all, you should go to the path search/product, then you need to set href option to true and pageVariable option to 'page'.
Unfortunately, the last version is not working as you meant (need to think how to handle this case).

@eugenesimakin
Copy link
Collaborator

By the way, which version do you using?

@mete89
Copy link

mete89 commented Feb 16, 2017

@esimakin I'm on the version 1.4.1. I implemented what you said and in every page anchors are generated.
If I enter the url xyx.com/abc?page=1 then all numbers get anchors like xyx.com/abc?page=2 etc.

But if there is no page number such as xyz.com/abc then all anchors become xyz.com/abc

Could we add query strings to anchors if there is no query string for the page but we set href: true and pageVariable to something?

@preflightech
Copy link

preflightech commented Mar 11, 2017

@mete89 I had exact same issue a few moments ago. If I go to localhost/?page=1 then everything works as intended, however if I go to the root, it won't generate correct because the RegEx doesn't find a query string to replace the variables of. The solution for me was the following.

In the buildItem: function (type, page) function, add the following:

if (this.options.defaultHref) {
	$itemContainer.append($itemContent.attr('href', this.options.defaultHref + page).addClass(this.options.anchorClass).html(itemText));
} else {
	$itemContainer.append($itemContent.attr('href', this.makeHref(page)).addClass(this.options.anchorClass).html(itemText));
}

And when you initilize the plugin, you can just add your default href path as following:

startPage: 1,
pageVariable: 'page',
visiblePages: 5,
href: true,
defaultHref: '/?page=',

Works fine now.

Edit: I have submitted a pull request with my fix.

Edit 2: I have a better fix, with no new options needed, and it also support multiple GET queries and replaces pageVariable correctly:

makeHref: function (page) {
    if (this.options.href) {
        var queryString = this.generateQueryString(page);
        if (!queryString) {
            return '?' + this.options.pageVariable + '=' + page;
        } else {
            if (queryString.indexOf(this.options.pageVariable) === -1) {
                return queryString + '&' + this.options.pageVariable + '=' + page;
            } else {
                return queryString;
            }
        }
    } else {
        return '#';
    }
},

@Ejilarasan
Copy link

How can we add the same pagination in top and bottom of the page?.
For single position its working fine but for top and bottom, only one pagination is displayed.

If trying to add pagination with 2 different id's, it's not affecting the page number of each other.

Let me know if any solution for it.

@eugenesimakin
Copy link
Collaborator

eugenesimakin commented Feb 7, 2018 via email

@Ejilarasan
Copy link

Thanks a lot .... working great !!!!

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

No branches or pull requests

5 participants