PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/chapters/10-pagination.md

https://github.com/bbt123/backbone-fundamentals
Markdown | 553 lines | 387 code | 166 blank | 0 comment | 0 complexity | 044774bd6f825878ecdcc1aafea43e13 MD5 | raw file
  1. # Paginating Backbone.js Requests & Collections
  2. ## Introduction
  3. Pagination is a ubiquitous problem we often find ourselves needing to solve on the web - perhaps most predominantly when working with service APIs and JavaScript-heavy clients which consume them. It's also a problem that is often under-refined as most of us consider pagination relatively easy to get right. This isn't however always the case as pagination tends to get more tricky than it initially seems.
  4. Before we dive into solutions for paginating data for your Backbone applications, let's define exactly what we consider pagination to be:
  5. Pagination is a control system allowing users to browse through pages of search results (or any type of content) which is continued. Search results are the canonical example, but pagination today is found on news sites, blogs, and discussion boards, often in the form of Previous and Next links. More complete pagination systems offer granular control of the specific pages you can navigate to, giving the user more power to find what they are looking for.
  6. It isn't a problem limited to pages requiring some visual controls for pagination either - sites like Facebook, Pinterest, and Twitter have demonstrated that there are many contexts where infinite paging is also useful. Infinite paging is, of course, when we pre-fetch (or appear to pre-fetch) content from a subsequent page and add it directly to the user’s current page, making the experience feel "infinite".
  7. Pagination is very context-specific and depends on the content being displayed. In the Google search results, pagination is important as they want to offer you the most relevant set of results in the first 1-2 pages. After that, you might be a little more selective (or random) with the page you choose to navigate to. This differs from cases where you'll want to cycle through consecutive pages for (e.g., for a news article or blog post).
  8. Pagination is almost certainly content and context-specific, but as Faruk Ates has [previously](https://gist.github.com/mislav/622561) pointed out the principles of good pagination apply no matter what the content or context is. As with everything extensible when it comes to Backbone, you can write your own pagination to address many of these content-specific types of pagination problems. That said, you'll probably spend quite a bit of time on this and sometimes you just want to use a tried and tested solution that just works.
  9. On this topic, we're going to go through a set of pagination components I (and a group of [contributors](https://github.com/addyosmani/backbone.paginator/contributors)) wrote for Backbone.js, which should hopefully come in useful if you're working on applications which need to page Backbone Collections. They're part of an extension called [Backbone.Paginator](http://github.com/addyosmani/backbone.paginator).
  10. ### Backbone.Paginator
  11. **Note:** As of Backbone.Paginator [2.0](https://github.com/backbone-paginator/backbone.paginator/releases), the API to
  12. the project has changed and includes updated which break backwards compatibility. The below section refers to Backbone.Paginator
  13. 1.0 which can still be downloaded [here](https://github.com/backbone-paginator/backbone.paginator/releases/tag/v1.0.0).
  14. When working with data on the client-side, the three types of pagination we are most likely to run into are:
  15. **Requests to a service layer (API)** - For example, query for results containing the term 'Paul' - if 5,000 results are available only display 20 results per page (leaving us with 250 possible result pages that can be navigated to).
  16. This problem actually has quite a great deal more to it, such as maintaining persistence of other URL parameters (e.g sort, query, order) which can change based on a user's search configuration in a UI. One also has to think of a clean way of hooking views up to this pagination so you can easily navigate between pages (e.g., First, Last, Next, Previous, 1,2,3), manage the number of results displayed per page and so on.
  17. **Further client-side pagination of data returned -** e.g we've been returned a JSON response containing 100 results. Rather than displaying all 100 to the user, we only display 20 of these results within a navigable UI in the browser.
  18. Similar to the request problem, client-pagination has its own challenges like navigation once again (Next, Previous, 1,2,3), sorting, order, switching the number of results to display per page and so on.
  19. **Infinite results** - with services such as Facebook, the concept of numeric pagination is instead replaced with a 'Load More' or 'View More' button. Triggering this normally fetches the next 'page' of N results but rather than replacing the previous set of results loaded entirely, we simply append to them instead.
  20. A request pager which simply appends results in a view rather than replacing on each new fetch is effectively an 'infinite' pager.
  21. **Let's now take a look at exactly what we're getting out of the box:**
  22. Backbone.Paginator is a set of opinionated components for paginating collections of data using Backbone.js. It aims to provide both solutions for assisting with pagination of requests to a server (e.g an API) as well as pagination of single-loads of data, where we may wish to further paginate a collection of N results into M pages within a view.
  23. ![](img/paginator-ui.png)
  24. Backbone.Paginator supports two main pagination components:
  25. * **Backbone.Paginator.requestPager**: For pagination of requests between a client and a server-side API
  26. * **Backbone.Paginator.clientPager**: For pagination of data returned from a server which you would like to further paginate within the UI (e.g 60 results are returned, paginate into 3 pages of 20)
  27. ### Live Examples
  28. If you would like to look at examples built using the components included in the project, links to official demos are included below and use the Netflix API so that you can see them working with an actual data source.
  29. * [Backbone.Paginator.requestPager()](http://addyosmani.github.com/backbone.paginator/examples/netflix-request-paging/index.html)
  30. * [Backbone.Paginator.clientPager()](http://addyosmani.github.com/backbone.paginator/examples/netflix-client-paging/index.html)
  31. * [Infinite Pagination (Backbone.Paginator.requestPager())](http://addyosmani.github.com/backbone.paginator/examples/netflix-infinite-paging/index.html)
  32. * [Diacritic Plugin](http://addyosmani.github.com/backbone.paginator/examples/google-diacritic/index.html)
  33. ##Paginator.requestPager
  34. In this section we're going to walk through using the requestPager. You would use this component when working with a service API which itself supports pagination. This component allows users to control the pagination settings for requests to this API (i.e navigate to the next, previous, N pages) via the client-side.
  35. The idea is that pagination, searching, and filtering of data can all be done from your Backbone application without the need for a page reload.
  36. ![](img/paginator-request.png)
  37. ####1. Create a new Paginated collection
  38. First, we define a new Paginated collection using `Backbone.Paginator.requestPager()` as follows:
  39. ```javascript
  40. var PaginatedCollection = Backbone.Paginator.requestPager.extend({
  41. ```
  42. ####2. Set the model for the collection as normal
  43. Within our collection, we then (as normal) specify the model to be used with this collection followed by the URL (or base URL) for the service providing our data (e.g the Netflix API).
  44. ```javascript
  45. model: model,
  46. ```
  47. ####3. Configure the base URL and the type of the request
  48. We need to set a base URL. The `type` of the request is `GET` by default, and the `dataType` is `jsonp` in order to enable cross-domain requests.
  49. ```javascript
  50. paginator_core: {
  51. // the type of the request (GET by default)
  52. type: 'GET',
  53. // the type of reply (jsonp by default)
  54. dataType: 'jsonp',
  55. // the URL (or base URL) for the service
  56. // if you want to have a more dynamic URL, you can make this a function
  57. // that returns a string
  58. url: 'http://odata.netflix.com/Catalog/People(49446)/TitlesActedIn?'
  59. },
  60. ```
  61. ## Gotchas!
  62. If you use `dataType` **NOT** jsonp, please remove the callback custom parameter inside the `server_api` configuration.
  63. ####4. Configure how the library will show the results
  64. We need to tell the library how many items per page we would like to see, etc...
  65. ```javascript
  66. paginator_ui: {
  67. // the lowest page index your API allows to be accessed
  68. firstPage: 0,
  69. // which page should the paginator start from
  70. // (also, the actual page the paginator is on)
  71. currentPage: 0,
  72. // how many items per page should be shown
  73. perPage: 3,
  74. // a default number of total pages to query in case the API or
  75. // service you are using does not support providing the total
  76. // number of pages for us.
  77. // 10 as a default in case your service doesn't return the total
  78. totalPages: 10
  79. },
  80. ```
  81. ####5. Configure the parameters we want to send to the server
  82. Only the base URL won't be enough for most cases, so you can pass more parameters to the server.
  83. Note how you can use functions instead of hardcoded values, and you can also refer to the values you specified in `paginator_ui`.
  84. ```javascript
  85. server_api: {
  86. // the query field in the request
  87. '$filter': '',
  88. // number of items to return per request/page
  89. '$top': function() { return this.perPage },
  90. // how many results the request should skip ahead to
  91. // customize as needed. For the Netflix API, skipping ahead based on
  92. // page * number of results per page was necessary.
  93. '$skip': function() { return this.currentPage * this.perPage },
  94. // field to sort by
  95. '$orderby': 'ReleaseYear',
  96. // what format would you like to request results in?
  97. '$format': 'json',
  98. // custom parameters
  99. '$inlinecount': 'allpages',
  100. '$callback': 'callback'
  101. },
  102. ```
  103. ## Gotchas!
  104. If you use `$callback`, please ensure that you did use the jsonp as a `dataType` inside your `paginator_core` configuration.
  105. ####6. Finally, configure Collection.parse() and we're done
  106. The last thing we need to do is configure our collection's `parse()` method. We want to ensure we're returning the correct part of our JSON response containing the data our collection will be populated with, which below is `response.d.results` (for the Netflix API).
  107. You might also notice that we're setting `this.totalPages` to the total page count returned by the API. This allows us to define the maximum number of (result) pages available for the current/last request so that we can clearly display this in the UI. It also allows us to influence whether clicking say, a 'next' button should proceed with a request or not.
  108. ```javascript
  109. parse: function (response) {
  110. // Be sure to change this based on how your results
  111. // are structured (e.g d.results is Netflix specific)
  112. var tags = response.d.results;
  113. //Normally this.totalPages would equal response.d.__count
  114. //but as this particular NetFlix request only returns a
  115. //total count of items for the search, we divide.
  116. this.totalPages = Math.ceil(response.d.__count / this.perPage);
  117. return tags;
  118. }
  119. });
  120. });
  121. ```
  122. ####Convenience methods:
  123. For your convenience, the following methods are made available for use in your views to interact with the `requestPager`:
  124. * **Collection.goTo( n, options )** - go to a specific page
  125. * **Collection.nextPage( options )** - go to the next page
  126. * **Collection.prevPage( options )** - go to the previous page
  127. * **Collection.howManyPer( n )** - set the number of items to display per page
  128. **requestPager** collection's methods `.goTo()`, `.nextPage()` and `.prevPage()` are all extensions of the original [Backbone Collection.fetch() methods](http://documentcloud.github.com/backbone/#Collection-fetch). As so, they all can take the same option object as a parameter.
  129. This option object can use `success` and `error` parameters to pass a function to be executed after server answer.
  130. ```javascript
  131. Collection.goTo(n, {
  132. success: function( collection, response ) {
  133. // called is server request success
  134. },
  135. error: function( collection, response ) {
  136. // called if server request fail
  137. }
  138. });
  139. ```
  140. To manage callback, you could also use the [jqXHR](http://api.jquery.com/jQuery.ajax/#jqXHR) returned by these methods to manage callback.
  141. ```javascript
  142. Collection
  143. .requestNextPage()
  144. .done(function( data, textStatus, jqXHR ) {
  145. // called is server request success
  146. })
  147. .fail(function( data, textStatus, jqXHR ) {
  148. // called if server request fail
  149. })
  150. .always(function( data, textStatus, jqXHR ) {
  151. // do something after server request is complete
  152. });
  153. });
  154. ```
  155. If you'd like to add the incoming models to the current collection, instead of replacing the collection's contents, pass `{update: true, remove: false}` as options to these methods.
  156. ```javascript
  157. Collection.prevPage({ update: true, remove: false });
  158. ```
  159. ##Paginator.clientPager
  160. The clientPager is used to further paginate data that has already been returned by the service API. Say you've requested 100 results from the service and wish to split this into 5 pages of paginated results, each containing 20 results at a client level - the clientPager makes it trivial to do this.
  161. ![](img/paginator-client.png)
  162. Use the clientPager when you prefer to get results in a single "load" and thus avoid making additional network requests each time your users want to fetch the next "page" of items. As the results have all already been requested, it's just a case of switching between the ranges of data actually presented to the user.
  163. ####1. Create a new paginated collection with a model and URL
  164. As with `requestPager`, let's first create a new Paginated `Backbone.Paginator.clientPager` collection, with a model:
  165. ```javascript
  166. var PaginatedCollection = Backbone.Paginator.clientPager.extend({
  167. model: model,
  168. ```
  169. ####2. Configure the base URL and the type of the request
  170. We need to set a base URL. The `type` of the request is `GET` by default, and the `dataType` is `jsonp` in order to enable cross-domain requests.
  171. ```javascript
  172. paginator_core: {
  173. // the type of the request (GET by default)
  174. type: 'GET',
  175. // the type of reply (jsonp by default)
  176. dataType: 'jsonp',
  177. // the URL (or base URL) for the service
  178. url: 'http://odata.netflix.com/v2/Catalog/Titles?&'
  179. },
  180. ```
  181. ####3. Configure how the library will show the results
  182. We need to tell the library how many items per page we would like to see, etc...
  183. ```javascript
  184. paginator_ui: {
  185. // the lowest page index your API allows to be accessed
  186. firstPage: 1,
  187. // which page should the paginator start from
  188. // (also, the actual page the paginator is on)
  189. currentPage: 1,
  190. // how many items per page should be shown
  191. perPage: 3,
  192. // a default number of total pages to query in case the API or
  193. // service you are using does not support providing the total
  194. // number of pages for us.
  195. // 10 as a default in case your service doesn't return the total
  196. totalPages: 10,
  197. // The total number of pages to be shown as a pagination
  198. // list is calculated by (pagesInRange * 2) + 1.
  199. pagesInRange: 4
  200. },
  201. ```
  202. ####4. Configure the parameters we want to send to the server
  203. Only the base URL won't be enough for most cases, so you can pass more parameters to the server.
  204. Note how you can use functions instead of hardcoded values, and you can also refer to the values you specified in `paginator_ui`.
  205. ```javascript
  206. server_api: {
  207. // the query field in the request
  208. '$filter': 'substringof(\'america\',Name)',
  209. // number of items to return per request/page
  210. '$top': function() { return this.perPage },
  211. // how many results the request should skip ahead to
  212. // customize as needed. For the Netflix API, skipping ahead based on
  213. // page * number of results per page was necessary.
  214. '$skip': function() { return this.currentPage * this.perPage },
  215. // field to sort by
  216. '$orderby': 'ReleaseYear',
  217. // what format would you like to request results in?
  218. '$format': 'json',
  219. // custom parameters
  220. '$inlinecount': 'allpages',
  221. '$callback': 'callback'
  222. },
  223. ```
  224. ####5. Finally, configure Collection.parse() and we're done
  225. And finally we have our `parse()` method, which in this case isn't concerned with the total number of result pages available on the server as we have our own total count of pages for the paginated data in the UI.
  226. ```javascript
  227. parse: function (response) {
  228. var tags = response.d.results;
  229. return tags;
  230. }
  231. });
  232. ```
  233. ####Convenience methods:
  234. As mentioned, your views can hook into a number of convenience methods to navigate around UI-paginated data. For `clientPager` these include:
  235. * **Collection.goTo(n, options)** - go to a specific page
  236. * **Collection.prevPage(options)** - go to the previous page
  237. * **Collection.nextPage(options)** - go to the next page
  238. * **Collection.howManyPer(n)** - set how many items to display per page
  239. * **Collection.setSort(sortBy, sortDirection)** - update sort on the current view. Sorting will automatically detect if you're trying to sort numbers (even if they're strored as strings) and will do the right thing.
  240. * **Collection.setFilter(filterFields, filterWords)** - filter the current view. Filtering supports multiple words without any specific order, so you'll basically get a full-text search ability. Also, you can pass it only one field from the model, or you can pass an array with fields and all of them will get filtered. Last option is to pass it an object containing a comparison method and rules. Currently, only ```levenshtein``` method is available.
  241. The `goTo()`, `prevPage()`, and `nextPage()` functions do not require the `options` param since they will be executed synchronously. However, when specified, the success callback will be invoked before the function returns. For example:
  242. ```javascript
  243. nextPage(); // this works just fine!
  244. nextPage({success: function() { }}); // this will call the success function
  245. ```
  246. The options param exists to preserve (some) interface unification between the requestPaginator and clientPaginator so that they may be used interchangeably in your Backbone.Views.
  247. ```javascript
  248. this.collection.setFilter(
  249. {'Name': {cmp_method: 'levenshtein', max_distance: 7}}
  250. , "Amreican P" // Note the switched 'r' and 'e', and the 'P' from 'Pie'
  251. );
  252. ```
  253. Also note that the Levenshtein plugin should be loaded and enabled using the ```useLevenshteinPlugin``` variable.
  254. Last but not less important: performing Levenshtein comparison returns the ```distance``` between two strings. It won't let you *search* lengthy text.
  255. The distance between two strings means the number of characters that should be added, removed or moved to the left or to the right so the strings get equal.
  256. That means that comparing "Something" in "This is a test that could show something" will return 32, which is bigger than comparing "Something" and "ABCDEFG" (9).
  257. Use Levenshtein only for short texts (titles, names, etc).
  258. * **Collection.doFakeFilter(filterFields, filterWords)** - returns the models count after fake-applying a call to ```Collection.setFilter```.
  259. * **Collection.setFieldFilter(rules)** - filter each value of each model according to `rules` that you pass as argument. Example: You have a collection of books with 'release year' and 'author'. You can filter only the books that were released between 1999 and 2003. And then you can add another `rule` that will filter those books only to authors who's name start with 'A'. Possible rules: function, required, min, max, range, minLength, maxLength, rangeLength, oneOf, equalTo, containsAllOf, pattern. Passing this an empty rules set will remove any FieldFilter rules applied.
  260. ```javascript
  261. my_collection.setFieldFilter([
  262. {field: 'release_year', type: 'range', value: {min: '1999', max: '2003'}},
  263. {field: 'author', type: 'pattern', value: new RegExp('A*', 'igm')}
  264. ]);
  265. //Rules:
  266. //
  267. //var my_var = 'green';
  268. //
  269. //{field: 'color', type: 'equalTo', value: my_var}
  270. //{field: 'color', type: 'function', value: function(field_value){ return field_value == my_var; } }
  271. //{field: 'color', type: 'required'}
  272. //{field: 'number_of_colors', type: 'min', value: '2'}
  273. //{field: 'number_of_colors', type: 'max', value: '4'}
  274. //{field: 'number_of_colors', type: 'range', value: {min: '2', max: '4'} }
  275. //{field: 'color_name', type: 'minLength', value: '4'}
  276. //{field: 'color_name', type: 'maxLength', value: '6'}
  277. //{field: 'color_name', type: 'rangeLength', value: {min: '4', max: '6'}}
  278. //{field: 'color_name', type: 'oneOf', value: ['green', 'yellow']}
  279. //{field: 'color_name', type: 'pattern', value: new RegExp('gre*', 'ig')}
  280. //{field: 'color_name', type: 'containsAllOf', value: ['green', 'yellow', 'blue']}
  281. ```
  282. * **Collection.doFakeFieldFilter(rules)** - returns the models count after fake-applying a call to ```Collection.setFieldFilter```.
  283. ####Implementation notes:
  284. You can use some variables in your ```View``` to represent the actual state of the paginator.
  285. * ```totalUnfilteredRecords``` - Contains the number of records, including all records filtered in any way. (Only available in ```clientPager```)
  286. * ```totalRecords``` - Contains the number of records
  287. * ```currentPage``` - The actual page were the paginator is at.
  288. * ```perPage``` - The number of records the paginator will show per page.
  289. * ```totalPages``` - The number of total pages.
  290. * ```startRecord``` - The position of the first record shown in the current page (eg 41 to 50 from 2000 records) (Only available in ```clientPager```)
  291. * ```endRecord``` - The position of the last record shown in the current page (eg 41 to 50 from 2000 records) (Only available in ```clientPager```)
  292. * ```pagesInRange``` - The number of pages to be drawn on each side of the current page. So if ```pagesInRange``` is 3 and ```currentPage``` is 13 you will get the numbers 10, 11, 12, 13(selected), 14, 15, 16.
  293. ```html
  294. <!-- sample template for pagination UI -->
  295. <script type="text/html" id="tmpServerPagination">
  296. <div class="row-fluid">
  297. <div class="pagination span8">
  298. <ul>
  299. <% _.each (pageSet, function (p) { %>
  300. <% if (currentPage == p) { %>
  301. <li class="active"><span><%= p %></span></li>
  302. <% } else { %>
  303. <li><a href="#" class="page"><%= p %></a></li>
  304. <% } %>
  305. <% }); %>
  306. </ul>
  307. </div>
  308. <div class="pagination span4">
  309. <ul>
  310. <% if (currentPage > firstPage) { %>
  311. <li><a href="#" class="serverprevious">Previous</a></li>
  312. <% }else{ %>
  313. <li><span>Previous</span></li>
  314. <% }%>
  315. <% if (currentPage < totalPages) { %>
  316. <li><a href="#" class="servernext">Next</a></li>
  317. <% } else { %>
  318. <li><span>Next</span></li>
  319. <% } %>
  320. <% if (firstPage != currentPage) { %>
  321. <li><a href="#" class="serverfirst">First</a></li>
  322. <% } else { %>
  323. <li><span>First</span></li>
  324. <% } %>
  325. <% if (totalPages != currentPage) { %>
  326. <li><a href="#" class="serverlast">Last</a></li>
  327. <% } else { %>
  328. <li><span>Last</span></li>
  329. <% } %>
  330. </ul>
  331. </div>
  332. </div>
  333. <span class="cell serverhowmany"> Show <a href="#"
  334. class="selected">18</a> | <a href="#" class="">9</a> | <a href="#" class="">12</a> per page
  335. </span>
  336. <span class="divider">/</span>
  337. <span class="cell first records">
  338. Page: <span class="label"><%= currentPage %></span> of <span class="label"><%= totalPages %></span> shown
  339. </span>
  340. </script>
  341. ```
  342. ### Plugins
  343. **Diacritic.js**
  344. A plugin for Backbone.Paginator that replaces diacritic characters (`´`, `˝`, `̏`, `˚`,`~` etc.) with characters that match them most closely. This is particularly useful for filtering.
  345. ![](img/paginator-dia.png)
  346. To enable the plugin, set `this.useDiacriticsPlugin` to true, as can be seen in the example below:
  347. ```javascript
  348. Paginator.clientPager = Backbone.Collection.extend({
  349. // Default values used when sorting and/or filtering.
  350. initialize: function(){
  351. this.useDiacriticsPlugin = true; // use diacritics plugin if available
  352. ...
  353. ```
  354. ### Bootstrapping
  355. By default, both the clientPager and requestPager will make an initial request to the server in order to populate their internal paging data. In order to avoid this additional request, it may be beneficial to bootstrap your Backbone.Paginator instance from data that already exists in the dom.
  356. **Backbone.Paginator.clientPager:**
  357. ```javascript
  358. // Extend the Backbone.Paginator.clientPager with your own configuration options
  359. var MyClientPager = Backbone.Paginator.clientPager.extend({paginator_ui: {}});
  360. // Create an instance of your class and populate with the models of your entire collection
  361. var aClientPager = new MyClientPager([{id: 1, title: 'foo'}, {id: 2, title: 'bar'}]);
  362. // Invoke the bootstrap function
  363. aClientPager.bootstrap();
  364. ```
  365. Note: If you intend to bootstrap a clientPager, there is no need to specify a 'paginator_core' object in your configuration (since you should have already populated the clientPager with the entirety of its necessary data)
  366. **Backbone.Paginator.requestPager:**
  367. ```javascript
  368. // Extend the Backbone.Paginator.requestPager with your own configuration options
  369. var MyRequestPager = Backbone.Paginator.requestPager.extend({paginator_ui: {}});
  370. // Create an instance of your class with the first page of data
  371. var aRequestPager = new MyRequestPager([{id: 1, title: 'foo'}, {id: 2, title: 'bar'}]);
  372. // Invoke the bootstrap function and configure requestPager with 'totalRecords'
  373. aRequestPager.bootstrap({totalRecords: 50});
  374. ```
  375. Note: Both the clientPager and requestPager ```bootstrap``` function will accept an options param that will be extended by your Backbone.Paginator instance. However the 'totalRecords' property will be set implicitly by the clientPager.
  376. [More on Backbone bootstrapping](http://ricostacruz.com/backbone-patterns/#bootstrapping_data)
  377. ### Styling
  378. You're of course free to customize the overall look and feel of the paginators as much as you wish. By default, all sample applications make use of the [Twitter Bootstrap](http://twitter.github.com/bootstrap) for styling links, buttons and drop-downs.
  379. CSS classes are available to style record counts, filters, sorting and more:
  380. ![](img/paginator-styling2.png)
  381. Classes are also available for styling more granular elements like page counts within `breadcrumb > pages` e.g `.page`, `.page selected`:
  382. ![](img/paginator-classes.png)
  383. There's a tremendous amount of flexibility available for styling and as you're in control of templating too, your paginators can be made to look as visually simple or complex as needed.
  384. ### Conclusions
  385. Although it's certainly possible to write your own custom pagination classes to work with Backbone Collections, Backbone.Paginator tries to take care of much of this for you.
  386. It's highly configurable, avoiding the need to write your own paging when working with Collections of data sourced from your database or API. Use the plugin to help tame large lists of data into more manageable, easily navigatable, paginated lists.
  387. Additionally, if you have any questions about Backbone.Paginator (or would like to help improve it), feel free to post to the project [issues](https://github.com/addyosmani/backbone.paginator) list.