morlandi / django-ajax-datatable

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

Question about filters #120

Closed houda1998 closed 9 months ago

houda1998 commented 9 months ago

Hi, I'm trying django-ajax-datatable for the first time and I'm struggling with Filtering single columns, the filters do not display Capture d’écran 2023-09-12 115011

here is my view : `class VacationAjaxDatatableView(AjaxDatatableView): model = DemandeConge title = 'Mes demandes de congé' search_values_separator = '+' show_column_filters = True full_row_select = False initial_order = [["type_conge", "asc"], ]

column_defs = [
    # AjaxDatatableView.render_row_tools_column_def(),
    {
        'name': 'type_conge',  # required
        'title': 'Type congé',  # optional: default = field verbose_name or column name
        # 'choices': False,  # see `Filtering single columns` below
        # 'initialSearchValue': None,  # see `Filtering single columns` below
        # 'autofilter': False,  # see `Filtering single columns` below
        # 'boolean': False,  # treat calculated column as BooleanField
        # 'lookup_field': '__icontains',
        'searchable': True,
        'visible': True,
        # used for searches; default: '__iexact' for columns with choices, '__icontains' in all other cases
    }
    , {
        'name': 'start_date',  # required
        'title': 'Date début',  # optional: default = field verbose_name or column name
        # 'placeholder': False,  # ???
        # 'choices': None,  # see `Filtering single columns` below
        # 'initialSearchValue': None,  # see `Filtering single columns` below
        # 'autofilter': False,  # see `Filtering single columns` below
        # 'boolean': False,  # treat calculated column as BooleanField
        'lookup_field': '__icontains',
        'searchable': True
    },
    {
        'name': 'end_date',  # required
        'title': 'Date fin',  # optional: default = field verbose_name or column name
        # 'placeholder': False,  # ???
        # 'choices': None,  # see `Filtering single columns` below
        # 'initialSearchValue': None,  # see `Filtering single columns` below
        # 'autofilter': False,  # see `Filtering single columns` below
        # 'boolean': False,  # treat calculated column as BooleanField
        'lookup_field': '__icontains',
        'searchable': True
    },
]

def get_initial_queryset(self, request=None):
    user = self.request.user
    if not self.request.user.is_authenticated:
        raise PermissionDenied

    queryset = DemandeConge.objects.filter(employe=user.userprofile).all()
    return queryset`

thanks for your help