Skip to content
This repository has been archived by the owner on Jul 4, 2021. It is now read-only.

Django Rest Framework - Default OrderingFilter #264

Open
robert-malai opened this issue Nov 12, 2014 · 2 comments
Open

Django Rest Framework - Default OrderingFilter #264

robert-malai opened this issue Nov 12, 2014 · 2 comments

Comments

@robert-malai
Copy link

The way the query params are build for sorting purposes doesn't play nice with the default filtering solution from Django Rest Framework.

Backbone Paginator is using two parameters to describe the filtering, where DRF is using only one, in which he's expecting a list of fields in the form ordering='column' or ordering='-column' for ascending, respectively descending sorting.

Would it be possible to move the params building code out in an overridable function ? at the moment, it resides in the fetch function, forcing me to override the whole function.

@robert-malai
Copy link
Author

Kind of a patch solution:

state: {
    pageSize: 25
},

queryParams: {
    totalRecords: null,
    totalPages: null,
    pageSize: 'page_size',
    // this is special for DRF OrderingFilter
    ordering: function () {
        var sortKey = this.state.sortKey, order = this.state.order;
        if (sortKey && order !== 0) {
            return (order === 1 ? '-' : '') + sortKey;
        }
        return null;
    }
},

With this, I still send the sortKey and order params, I don't know how to block them.

@aleray
Copy link

aleray commented Feb 7, 2018

Something like this?

            state: {
                pageSize: 25,
                firstPage: 1,
                currentPage: 1,
                sortKey: "created_at",
                order: -1
            },

            queryParams: {
                currentPage: "page",
                pageSize: "page_size",
                totalRecords: "count",
                order: null,
                sortKey: "ordering",
                ordering: function () {
                    var sortKey = this.state.sortKey, order = this.state.order;
                    if (sortKey && order !== 0) {
                        return (order === 1 ? '-' : '') + sortKey;
                    }
                    return null;
                }
            }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants