Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order By change ? Default value ? #42

Open
Carlit-Auh opened this issue Apr 22, 2024 · 3 comments
Open

Order By change ? Default value ? #42

Carlit-Auh opened this issue Apr 22, 2024 · 3 comments

Comments

@Carlit-Auh
Copy link

Hello,
I use adonisJS 6, I installed the library to manage my filters which is very practical. Thanks for that.

However, I've noticed that using a filter on my model changes the sort in which I receive my data.

I have several questions: is it normal for the sorting to change? Have I made a configuration error?
And can I apply a default sorting filter to all the models and then put an orderBy on each of the queries?

Currently, I've created a filter that adds a like on a text field, very simple and I've added the import of this filter in my model to use the .filter in my controller.

Sorry if there's any documentation on this, I haven't found any information on this.
Thanks in advance.

@LookinGit
Copy link
Member

Hello @Carlit-Auh
This addon should not change the order of the data. Can you provide an example of this behavior in your code?

@DrummerSi
Copy link

I second the notion to add a default "filter"...

For example.. If I return a list of users.. By default I only want to return "active" users, and allow the user to selected "disabled" if they need to view those records.

@LookinGit
Copy link
Member

@DrummerSi your case:

// users_controller.ts

async index({ request }: HttpContext): Promise<ModelPaginatorContract<User>> {
  const { page = 1, active = true, ...input } = request.qs()
  return User.filter({ active, ...input }).paginate(page, 15)
}

default value for active == default filter

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

No branches or pull requests

3 participants