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

Choice option in column filter: instead of distinc values from db table only displayed data #90

Open
doctsh opened this issue Jul 8, 2022 · 4 comments
Labels
question Further information is requested

Comments

@doctsh
Copy link

doctsh commented Jul 8, 2022

Hi
I have started using this wonderful package in my application. I am stuck with one place where choices are enabled and it shows models field choices or db table distinct values.
But when data is filtered for a user if we can restrict the column dropdown options to distinct values of what is being served through initial queryset will be more opt than collecting from entire db.

I know this can't be an issue and could be improvement. Considering data protection so as other users dont see full list of distinct values is important.

Is there anyway to achieve this? or am I doing anything wrong?

@morlandi
Copy link
Owner

morlandi commented Jul 8, 2022

Hello,
you could try settings autofilter = True which does exactly what you want:

https://github.com/morlandi/django-ajax-datatable#id12

but it might be ignored when Field has chioices ... I'm not sure about this details.
I'ld give it a try

@morlandi morlandi added the question Further information is requested label Jul 8, 2022
@doctsh
Copy link
Author

doctsh commented Jul 8, 2022

Thank you so much for prompt reply.
If I remove choices then autofilter does not work (filter becomes textbox), if I include choices then autofilter takes unique db field....
my field is foreign field so i did mention this as:

        {'name': 'topic', 'visible': True, 'searchable': True, 'orderable': True, 'choices': True,
         'foreign_field': 'topic__topic', 'autofilter': True, },

@morlandi
Copy link
Owner

morlandi commented Jul 8, 2022

The idea behind this is that if you start to fill a brand new table, no values are available yet, thus the only chance to help the user is to show the list of choices associated with the Field.
In my project I tend to use choices with a limited number of values, so it's not a big problem; when the number of choices is significant, I rather opt to have a separate "lookup" table and a FK.

I do undestand that there might be cases where this solution is not the optimal choice.

@doctsh
Copy link
Author

doctsh commented Jul 8, 2022

Yes, you are right. I moved a filter out of column filtering and filter using select from shortlisted items:

image

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

No branches or pull requests

2 participants