Question: how to handle setting filters/sorting, then fetching data, then changing filtering/sorting? #151

Closed
scottsd opened this Issue Feb 28, 2013 · 2 comments

3 participants

@scottsd

Howdy,

I want to set values perPage, where, sortField, then trigger fetch. Right now a fetch is triggered after each of these, and there's no way to set "where".

As a workaround, I use this

myCollection = new UsersCollection() //this extends requestPaginator
myCollection.paginator_ui.perPage = 5
myCollection.paginator_ui.where = 'age > 16'
myCollection.paginator_ui.sortField = 'name'

However, when initializing UsersCollection again somewhere else, it has the changed properties instead of defaults.
We also need to change where/sorting depending on user actions, and re-fetch.

How should this basic workflow be handled? Would be great to have an example in docs.

@phillycoder

if this is requestPager, Did you try using server_api instead? For example here orderDir is a custom property which i added in my application.

            server_api: {

                page: function(){
                    this.trigger('beforeLoad', this);

                    if(this.currentPage){
                        return this.currentPage;
                    } else {
                        return 1;
                    }
                },

                'orderby': function() {
                                if(this.sortField === undefined)
                                    return 'ReleaseYear';
                                return this.sortField;
                            },

                'orderdir': function() {
                                if(this.sortDirection === undefined)
                                    return 'asc';
                                return this.sortDirection;
                            },

                pageSize: function(){return this.perPage}
            }
@addyosmani
Backbone Paginator member

Closing as there hasn't been any further activity here since Feb.

@addyosmani addyosmani closed this May 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment