Notes

Linux, WebDev and other…

Collection pagination view for Backbone with jQuery Mobile

Here is a view that listens to backbone collection “reset” event and renders/refreshes pagination. Template is based on jquery mobile, but can be easily changed. General information about mixing backbone with jquery mobile is here. I just use it like bootstrap, but in the end of render function I manually call $el.trigger(‘create’) to initialize markup (I don’t have fancy page transitions).

Underscore template:

CSS Part:

 

Paginated collection is also required to change page and read state (firstPage, totalPages etc). I used my own with “changePage” method and “state” object, which makes AJAX request every page change. For test purposes this one also looks good.

Example usage (inside render of parent view):

And finally screen:

pagination

 

 

, , ,

Leave a Reply

Your email address will not be published. Required fields are marked *