-
Notifications
You must be signed in to change notification settings - Fork 64
[Feature Request] How can filters be applied to PageableCollection? #75
Comments
My working solution is to not use Backbone.PageableCollection for my full collections,
It'd be good to know if there is a better approach. Or, would a |
There's a much simplified ClientSideFilter in Backgrid's master now, maybe you can take a look to get some ideas. It's very simple. As to adding view/in-place filtering capabilities to backbone-pageable, I think the answer will probably be a no. I consider backbone-pageable is now feature-complete and in maintenance mode. There are already 28 Underscore methods attached to both As you may have discovered already, resetting |
BTW, you can attach extra parameters to |
Great to know, thanks, I'll be using that soon. I'm using ClientSideFilter and PageableCollection along with my own collection filters. It's working splendidly. FWIW: Pre-filtering was the key for me, instead of basing my collections off of PageableCollection. The pattern I'm using is a collection "blessed" with a
|
This sounds interesting. I'm curious does your implementation work for all 3 modes? Can I add a couple of filters and have a server mode PageableCollection send out extra query params? |
No. If only I had such foresight. If you're feeling brave, here's more context in how I'm using it with the PageableCollection: I haven't tried it, yet, but I imagine it wouldn't take much for the filters to include something like 'toQueryParams' to use in the |
In my case I was needing server search thru backbone-pagebale. Maybe someone could use it: Add query as state: state: {
...
query: {}
...
}, add query to queryParams: queryParams: {
...
query: function() { return this.state.query; },
...
} add method to set query: setQuery: function (query, page_size) {
var state = this.state;
if(query != state.query) {
state = _.clone(this._initState)
state.pageSize = page_size;
}
state = this.state = this._checkState(_.extend({}, state, {
query: query,
}));
}, |
josx, that's exactly what I'm looking for - but It's not quite working for me - where are you calling setQuery from? Any chance you could share a little more of your implementation code with me? |
Sorry about the delay: check here: https://github.com/inaes-tic/mbc-common/blob/master/models/Default.js searchOnServer function here: |
For what it's worth, I needed search/filter functionality for my Pageable collections as well and started out with extending the PageableCollection, but recently just forked and committed my own additions. There's still some work to do, but it's a good start for what I need, and might help some others. I merged in the filtering style of Backbone.Paginator so you can do things like: collection.addFilter({
field : 'my_attr',
type: 'contains',
value : 'some value'
}) I added built in filter types for client collections, and then for server/infinite mode I map the filter types to query params, so the above code might make a query like this:
It's setup to play well with multiple filters as well, and will turn the query params into arrays like:
Searching can also pretty simple and is configurable with default fields to search on: collection.defaultSearchField = 'my_attr';
collection.search('my query'); In server/infinite mode it would make a call something like this:
|
In the FAQ, it states, "...you can do filtering fairly easily with Backbone's built-in support for Underscore.js methods."
I am looking to do just that, but am not sure of a good approach that maintains accurate pagination state and model references across other views.
Is there an example of applying filters to a PageableCollection?
Here's the api I'm shooting for:
deserts would have a
_filters
object that could bemodified through
addFilter
,removeFilter
,clearFilters
methodsA bound backgrid and/or paginator would reflect state with the filters applied.
Probably through incorporating an interal
_applyFilters
, something like:Return to the full collection:
It's not clear to me how I can extend BackbonePageable to provide these filtering methods without overriding internal methods.
An example or suggestion in the documentation would be great.
Thank you for such a great project.
The text was updated successfully, but these errors were encountered: