morlandi / django-ajax-datatable

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

Hidden columns are possible to filter #20

Closed PetrDlouhy closed 3 years ago

PetrDlouhy commented 3 years ago

I wanted to add filter on hidden column by javascript, but even if I explicitly set the column as:

 {'name': 'is_private', 'visible': False, 'searchable': True},

it is not possible to filter single hidden column by Javascript calls like

javascript:$('#datatable_assets').DataTable().columns(16).search('window').draw();

I fixed this by overriding the searchable value:

    def filter_queryset(self, params, qs):
        # fix hidden column searchable
        params['column_links'][11].searchable = True
        return super().filter_queryset(params, qs)
morlandi commented 3 years ago

Searching in a hidden column is certainly something usefull. I'll fix it on first occasion.

morlandi commented 3 years ago

This is puzzling, since I double-checked it and it seems to work as expected. Sure, you have to explicitly set 'searchable': True when the column is hidden, since the default is: True if visible, False otherwise. But you already did this. Might be more related to searching in a boolean field? Could you please check again? I'm closing the issue now, but feel free to reopen it in case

PetrDlouhy commented 3 years ago

@morlandi Yes, I am searching in boolean field. I will investigate this more.

PetrDlouhy commented 3 years ago

I foregot to mention how I am searching/filtering the column. I changed it in description - I am using javascript to filter just the hidden column values.

I will try to investigate why this happens now.

PetrDlouhy commented 3 years ago

@morlandi I found what is the problem. There are switched parameters in the ColumnLink initialization in read_parameters. I will make PR.

morlandi commented 3 years ago

How surprising ! I just checked in the original project I started from; the bug is already there and dated 4 feb 2016:

https://github.com/monnierj/django-datatables-server-side/blob/master/django_datatables_server_side/views.py