Backbone.PageableCollection's fullCollection acts weird after reset

293 Views Asked by At

I have a Backbone.Pageable collection on which I am trying to do a filter but and reset the collection with the filtered values but after the reset, collection.fullCollection has one less model than the original.

This is my collection:

var todoCollection = Backbone.PageableCollection.extend({
  mode:'client',
  search: function(letters){
    var self = this;
    if(letters === "") return this.fullCollection.models;

    var pattern = new RegExp(letters,"i");
    return this.fullCollection.filter(function(data) {
      return pattern.test(data.get("text"));
    });
  }
});

You can check at this fiddle here.

1

There are 1 best solutions below

3
On

Your search function should return an instance of todoCollection.

var todoCollection = Backbone.PageableCollection.extend({

mode:'client',
  search: function(letters){
    var self = this;
    if(letters === "") return this.fullCollection.models;

    var pattern = new RegExp(letters,"i");
    result =  this.fullCollection.filter(function(data) {
      return pattern.test(data.get("text"));
    });
    return new todoCollection(result);
  }

Working fiddle