Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paged collections in Backbone.js

What is the standard approach for paged collections in Backbone.js ? And how about sorting ? Does it support these features out of the box ? Do I need some sort of plugin ?

like image 468
Thilo Avatar asked Oct 29 '11 00:10

Thilo


People also ask

What is collections in Backbone JS?

A Backbone. js Collections are a group of related models. It is useful when the model is loading to the server or saving to the server. Collections also provide a helper function for performing computation against a list of models.

Is Backbone JS still used?

Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.

Is Backbone JS frontend or backend?

Backend Synchronization BackboneJS is use with the front-end and back-end systems, allows the synchronization with the backend to provide support to RESTful APIs.


1 Answers

None of these things are supported out of the box (Backbone is a thin library, not a big framework).

For pagination check Backbone JS Pagination

For sorting, the think you have in Backbone is defining a comparator on a collection: http://documentcloud.github.com/backbone/docs/backbone.html#section-53

So one approach would be to initialize your collection, and then when you have to change the order, change it's comparator and call collection.sort. This would trigger a reset event that you can listen for in your view and re-render.

like image 126
dira Avatar answered Sep 22 '22 03:09

dira