Skip to content

Commit

Permalink
Expand available methods on collection
Browse files Browse the repository at this point in the history
  • Loading branch information
farias-r7 committed Dec 18, 2015
1 parent 7eb6945 commit 9c191d2
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9c191d2

Please sign in to comment.