I'm comfortable with the comparator
function in Backbone.Collection
and I'm also comfortable with the idea of sorting a collection and then redrawing the whole thing from a view. However, I'm not looking for that here.
I've got a collection that has been sorted (upon load). One view listens to the collection and is responsible for iterating through it on "reset". The models of the collection have their own view. Nothing out of the ordinary here.
However, the user is able to edit each model in-line, potentially changing the value of the attribute that is featured in the comparator function. Obviously one solution would be to just clear the whole collection's view, re-sort the collection, and then redraw all the models' views. But I'd like to avoid doing that if possible.
Ideally, I should be able to remove the altered model from the collection's view and then re-insert it at its new, appropriate, position in the collection view (so I'm only doing one DOM removal and one DOM addition - rather than clearing and then redrawing the entire collection of models). I could of course do this manually, without any help from backbone, but I thought I'd ask if there are any features of backbone that could make it easier, or at least more streamlined. Doing this completely outside of backbone seems like a hack, and it won't look pretty.