HTML5, CSS3, jQuery, JSON, Responsive Design...

Backbone.js pagination for Domino

Michael Brown   October 13 2012 10:15:39 PM
Sometimes as a developer, you happen across a real gem.  Such a one is Addy Osmani's Backbone Paginator project.

By leveraging the very excellent backbone.js JavaScript library, the project takes all the pain out of paginating the data that you've pulled in from Ajax; not only presenting the data itself, but all the Prev, Next and 1, 2, 3, 4 links and so on.  Rather like this, in fact:

Image:Backbone.js pagination for Domino

All I've done is rework Addy's requestPager() example, which sources data from Netflix (with a Nicole Kidman angle!), and configured it to pull data from the somewhat more prosaic source of a Domino NAB.  Here's the results of my endevours and I don't mind saying that the results are rather remarkable. (Note: my dev server is a bit up and down at the moment, so bear with me while I get it fixed.)

The reason that "I don't mind saying" this is that so very little of this is my work!  Addy's done all the heavy lifting.  There wasn't any real development for me to do at all.  It was largely a matter of configuring the various parameters, as documented by Addy on his Github project page.  If you're not familiar with backbone.js, then you may find this heavy going, but I think you'll find that it's well worth the effort to learn it.

The collections/PaginatedCollection.js library is where I made most of the changes.  If you compare it against Addy's Netflix example code, you'll see how I've cut out or reworked a lot of stuff that wasn't needed for Domino, such as:
  • I changed the data source from JSONP to vanilla JSON, since I won't need to be going cross-server with a Domino NAB.
  • I swapped out Netflix parameters such as $Top and $Skip for their Domino ReadViewEntries equivalents, Start and Count.
  • I changed a lot of parameters to cater for the fact that a ReadViewEntries Count starts at 1, whereas a Netflix $Top starts at zero. (ReadViewEntries&Start=0 won't return anything useful for you.)
I think this could form the basis for reworking of my Web NAB Picker project from a few years back.  Watch this space!

Update 31/10/2012

As previously threatened, I have indeed rewritten the Web NAB Names Picker from the ground-up using Backbone Pagination as the basis.
No Comments Found