question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorting on the server

See original GitHub issue

It would be nice to add functionality to implement sorting on the server, something like that:

model.page(1).sorting({ name: 'desc' }).fetch() => ?page=1&sort=name&order=desc

or set all query params

model.queryParams({ page: 1, sort: 'name', order: 'desc' }).fetch() => ?page=1&sort=name&order=desc

it would be convenient to use with route

{ params: this.$route.query }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
rtheunissencommented, Nov 13, 2017

If you wanted to fetch a paginated collection with some sorting parameters, you could do it like this:

collection.set('sort', 'name');
collection.set('order', 'desc');

...

getFetchQuery() {
    return {
        page:  this.getPage(),
        sort:  this.get('sort'),
        order: this.get('order'),
    }
}
0reactions
rtheunissencommented, Dec 16, 2017

This in on Model:

    /**
     * Called when a save request resulted in a validation error.
     *
     * @param {Object} errors
     */
    onSaveValidationFailure(error) {
        let errors = error.getResponse().getValidationErrors();

        if ( ! _.isPlainObject(errors)) {
            throw new ResponseError(
                'Validation errors must be an object', error.getResponse());
        }

        this.setErrors(errors);

        Vue.set(this, 'fatal',  false);
        Vue.set(this, 'saving', false);
    }

What you could do is override setErrors, or we could implement a method like getValidationErrors(error) that might be a more appropriate override?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-Side and Client-Side Sorting and Filtering
When server-side filtering or sorting is performed, the application sends a query that is a modification of the starting query to the server....
Read more >
Sorting on the server or on the client? - Stack Overflow
First off, the database may already have indexes on the fields you want so it may be trivial for it to retrieve data...
Read more >
A server side external sorting and filtering example #2033
I myself was struggling with implementing a server-side sorting (data were a query to postgres) and came up with a solution that works...
Read more >
Server Side Sorting - SoftFluent
Server side sorting should be preferred in almost all cases to client side sorting, since server side sorting is handled in the data...
Read more >
serverSorting - API Reference - Kendo UI DataSource
By default, the data source performs sorting client-side. By default, the sort is sent to the server following jQuery conventions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found