I have a DataTable and I want to filter it's content depending on what user selects in form. Here is the sample of code I use:
$(document).on('click', '#filter_btn', filterList)
function filterList (event) {
event.preventDefault()
var form_data = $('.filter-form').serialize()
var url = window.location.origin + '/my-amazing-url/'
$('#dataTable-x').DataTable({
ajax: {
url: url,
type: 'get',
dataType: 'json',
data: form_data
}
})
$('#dataTable-x').DataTable().ajax.reload()
}
On server side Django returns following:
...
data = self.get_queryset().values()
return JsonResponse(data)
...
Yet nothing is changed. How should I modify the code? Thanks.