adonis-lucid-filter icon indicating copy to clipboard operation
adonis-lucid-filter copied to clipboard

Order By change ? Default value ?

Open Carlit-Auh opened this issue 10 months ago • 3 comments

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.

Carlit-Auh avatar Apr 22 '24 15:04 Carlit-Auh

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

LookinGit avatar May 05 '24 17:05 LookinGit

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.

DrummerSi avatar May 20 '24 17:05 DrummerSi

@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

LookinGit avatar May 23 '24 06:05 LookinGit