Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Posts
    139
    Thanks
    17
    Thanked 6 Times in 6 Posts

    Ajax Pagination with Google Feeds API

    Hi,

    I have a Pinterest feed that pulls in via Googles feed API.

    At the moment it is set to pull 50 pins through.

    For arguments sake, we will split this into 20 pins at a time.

    I would like this to be paginated if possible so that a view more button can be press/ or simple number pagination that will show more pins. I don't want to pull in all pins and then show/hide 20 at a time for example. I would like it to complete another Ajax request upon clicking more or 2 and get the next 20 pins. Also, the pins it already has got, if possible to not request these again. So your only requesting 20 at a time, not 20/40/60 etc.

    Is this possible ?

    Code can be viewed here - https://github.com/CHEWX/admire-spac...ets/js/main.js

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,233
    Thanks
    80
    Thanked 4,456 Times in 4,421 Posts
    I don't see why this is particularly difficult.

    First of all, if possible, change your settings to only pull in 20 pins at a time.

    And then all you have to do is have an array of pages, each element of which is in turn an array of 20 pins. That is:
    Code:
    var pages = [ ];
    pages[0] = ...array of the first 20 pins ...
    pages[32] = ...array of 20 pins for page 32 ...
    And so now all you have to do is check to see if the page desired by the user is null or not. If not, use the cached copy from the pages array. If null, then you need to go out and get those 20 pins.

    The coding is a bit more complex is you MUST get the pins in groups of 50, but not overwhelmingly so. If you can get them in groups of 40, 60, 80,100 that's about as easy as 20 at a time.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Posts
    139
    Thanks
    17
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by Old Pedant View Post
    The coding is a bit more complex is you MUST get the pins in groups of 50, but not overwhelmingly so. If you can get them in groups of 40, 60, 80,100 that's about as easy as 20 at a time.
    Thanks Old Pedant.

    No it doesn't need to be 50 - it's just set at that at the moment because I want to get as many as I can onto one page without having a killer load.

    20 will be perfect.

    Logic sounds the same as I was thinking, however writing that logic I am a bit lost. Will give it a bash however.

    Site is Admire Spaces | Inspiration from around the home so you can see what it is like at the moment.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,380
    Thanks
    11
    Thanked 592 Times in 572 Posts
    i don't think the feed api has a skip feature, so you're best off downloading 60 and make three pages in js. the extra feeds won't take up much extra space or time, so don't worry about grabbing too much.
    you would show the first 20 and wire some pagination buttons to show 21-40, and 41-60 upon click. you would just do a slice() on o.results, maybe var o2=o.results.slice(from, to); then each() o2.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Posts
    139
    Thanks
    17
    Thanked 6 Times in 6 Posts
    That's the way I have done it locally. However, it isn't something I would like to implement as when I get to 1000 pins. It's grabbing 1000 pins.

  • #6
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,380
    Thanks
    11
    Thanked 592 Times in 572 Posts
    Quote Originally Posted by CHEWX View Post
    That's the way I have done it locally. However, it isn't something I would like to implement as when I get to 1000 pins. It's grabbing 1000 pins.
    well, i don't disagree it's not the ebst, but if you rely on third-party servers instead of serving the pin info yourself, you'll have to play by the outside service's rules. you might consider using yahoo pipes and or YQL to aggregate feeds and skip over the first N items from a js call; i believe google's has far fewer options, but you can output a new feed from yahoo, and feed that to google, or get the feed data directly from yahoo as jsonp; either way will be a bit better than it is now. to do any better you'de need your own server.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •