From 9c191d25f8a4e8897bab2932d1c6c2b8bc89f2ae Mon Sep 17 00:00:00 2001 From: Fernando Arias Date: Fri, 18 Dec 2015 14:07:56 -0600 Subject: [PATCH 1/2] Expand available methods on collection --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/README.md b/README.md index 02fdd31..99c1543 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,61 @@ The button will be enabled if `activateOn` is set to: + 'one' - If only one row is selected +## Controlling Pagination +You can control the paginaton bar programatically by using the concenience methods available on the collection. + +``` +collection = this.tableController.controller +collection.goTo(n) +collection.nextPage(options) +collection.prevPage(options) +``` + +### Convenience methods: + + +* **Collection.goTo( n, options )** - go to a specific page +* **Collection.nextPage( options )** - go to the next page +* **Collection.prevPage( options )** - go to the previous page + + +**The collection's methods `.goTo()`, `.nextPage()` and `.prevPage()` are all extension of the original [Backbone Collection.fetch() method](http://documentcloud.github.com/backbone/#Collection-fetch). As so, they all can take the same option object as parameter. + +This option object can use `success` and `error` parameters to pass a function to be executed after server answer. + +```javascript +collection.goTo(n, { + success: function( collection, response ) { + // called is server request success + }, + error: function( collection, response ) { + // called if server request fail + } +}); +``` + +To manage callback, you could also use the [jqXHR](http://api.jquery.com/jQuery.ajax/#jqXHR) returned by these methods to manage callback. + +```javascript +collection + .requestNextPage() + .done(function( data, textStatus, jqXHR ) { + // called is server request success + }) + .fail(function( data, textStatus, jqXHR ) { + // called if server request fail + }) + .always(function( data, textStatus, jqXHR ) { + // do something after server request is complete + }); +}); +``` + +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. + +```javascript +collection.prevPage({ update: true, remove: false }); +``` ## Development From a69d66ea3016a6048d6b87b13589fbe8e845a31e Mon Sep 17 00:00:00 2001 From: Fernando Arias Date: Fri, 18 Dec 2015 14:12:42 -0600 Subject: [PATCH 2/2] Fix typos --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 99c1543..b362c0e 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,7 @@ The button will be enabled if `activateOn` is set to: + 'one' - If only one row is selected ## Controlling Pagination -You can control the paginaton bar programatically by using the concenience methods available on the collection. +You can control the pagination bar programatically by using the convenience methods available on the collection. ``` collection = this.tableController.controller