GithubHelp home page GithubHelp logo

Comments (6)

anthonycastelli avatar anthonycastelli commented on May 27, 2024 1

ToIf you're gonna override at the model level, it'll be something like this

extension MyModel: Paginatable {
    static var defaultPageSorts: [MyModel.Database.QuerySort] {
        return [
            // Option #1
            MyModel.Database.querySort(MyModel.Database.queryField(.keyPath(\ MyModel.name)), MyModel Database.querySortDirectionDescending),
            // Option #2
            (\MyModel.name).querySort()
        ]
    }
}

If you want to do it on a route level, it'll be done something like this:

return try query.paginate(for: req, [(\Allergy.name).querySort()])

from pagination.

anthonycastelli avatar anthonycastelli commented on May 27, 2024 1

I'm gonna go ahead and close this issue, but if you do run into issues, feel free to reopen this. 🙂

from pagination.

anthonycastelli avatar anthonycastelli commented on May 27, 2024

Overriding the defaultPageSorts will allow you to accomplish this on a per model basis.

static var defaultPageSorts: [Self.Database.QuerySort] { get }

If you want to do it on the fly, you can add your own sorts into the paginate method.

public func paginate(for req: Request, pageKey: String = Pagination.defaultPageKey, perPageKey: String = Pagination.defaultPerPageKey, _ sorts: [Result.Database.QuerySort] = Result.defaultPageSorts) throws -> Future<Page<Result>> {

from pagination.

andreascai avatar andreascai commented on May 27, 2024

@anthonycastelli I want to sort with Boolean value from certain column. Could you show me some example?

from pagination.

andreascai avatar andreascai commented on May 27, 2024

@anthonycastelli thanks for the help. I would try that later

from pagination.

andreascai avatar andreascai commented on May 27, 2024

@anthonycastelli

return try query.paginate(for: req, [(\Allergy.name).querySort()])

says Use of unresolved identifier 'query'.

from pagination.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.