adonis-lucid-filter
adonis-lucid-filter copied to clipboard
Order By change ? Default value ?
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.
Hello @Carlit-Auh This addon should not change the order of the data. Can you provide an example of this behavior in your code?
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 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