Include checkbox filter

Issue #23 invalid
Former user created an issue

Hello,

I have been very happily using datatables with django-datatables-view. However I would like to include a top level filter in the form of a checkbox (or tick box). I would like the checkbox to say "Show only active records" and then filter on one of the columns that specifies whether the row entry is active or inactive.

I am confused as to whether the filter should be applied on the front end or the server side and what approach to take in general. I am using DataTables 1.10.10 and django-datatables-view 1.13.0.

Comments (3)

  1. Maciej Wisniowski repo owner

    Simplest solution might be:

    • add a checkbox to your frontend html and then use ajax.data (http://datatables.net/reference/option/ajax.data) to pass checkbox's value to the server (see example 2 from the datatables docs linked above), eg: "data": function ( d ) {d.is_active = $('#is_active').prop('checked');}

    • override filter_queryset method from DjangoDatatablesView to apply is_active filter (you'll be able to get it's value from request like: is_active = self.request.POST.get('is_active'))

  2. Log in to comment