morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
211 stars 64 forks source link

Filter a Placeholder column #29

Closed mchessl closed 3 years ago

mchessl commented 3 years ago

Hello @morlandi,

Firstly bravo for this project, I am using it and it is so helpful.

I have an issue with filtering a Placeholder column. This column is a concatenation of its value and 3 other columns.

My column is defined as such {'name': 'column_1', 'placeholder': True, 'visible': True, 'searchable': True, 'orderable': False,}, And then def customize_row(self, row, obj): row['column_1'] = "

" + column_1+ column_2+ column_3+ column_4+ "
"

The filter only works for values issued from column_1, so I guess it is filtering before the row is assigned with my concatenation.

Is there a way I can filter a Placeholder column using its final value ?

Thanks a lot

ps : column_1 / 2/ / 3/ 4 being the different columns of my model

morlandi commented 3 years ago

Hello @mchessl , this doesn't seem to be feasible, since for performance reason filtering is always applied at the database level, and here your supplying and arbitrary text expression; the View has no idea that is is the result of concatenating values from different columns. I leave this issue open in case someone (including myself) would suggest a possible alternative solution (maybe playing with get_initial_queryset()). Cheers

mchessl commented 3 years ago

Thanks @morlandi for your answer !

morlandi commented 3 years ago

@mchessl , you might want to add a sidebar to implement your specific "multi-column" search as explained here:

https://github.com/morlandi/django-ajax-datatable#18add-a-sidebar-with-custom-filters

I'm going to close this issue; feel free to reopen it if you have any suggestion

mchessl commented 3 years ago

Ok thanks @morlandi