Django jquery Datatable: Requested unknown warning
Django jquery Datatable: Requested unknown warning
I'm trying to load jquery data table in Django. There is a json object return from view. I've got some mistake in loading data but i can't fix it.
Here is my code;
View (getData);
list = Datas.objects.all()
jsonData = serializers.serialize('json', list)
return JsonResponse({'data':jsonData})
JS;
$('#id_dataTable').dataTable({
"sAjaxSource": '/getData/',
"aoColumns": [
{"mData": "objectname"}
],
"aoColumnDefs": [
{
"aTargets": [0],
"sTitle": "Object Name",
"sClass": "align-center"
}
],
"bProcessing": true,
"sAjaxDataProp": "data",
"bServerSide": true,
"bPaginate": false
});
It returns javascript warning Requested unknown parameter "objectname".. In the network of the browser, it is seen that "data" is returned like this;
data: "[{"fields": {"objectname": "O1"}, "model": "my_app.datas", "pk": 3}]"
I think i need to get "fields" object but i couldn't.
and I also tried this;
View(getData);
list = Datas.objects.all()
jsonData = serializers.serialize('json', list)
return HttpResponse(jsonData, content_type='application/json')
$('#id_dataTable').dataTable({
'bProcessing': true,
"bServerSide": true,
"sAjaxSource": "/getData/",
"sAjaxDataProp": "data",
"columns": [
{ "data": "fields.objectname"}
]
});
HTML;
<table class="..." id="id_dataTable">
<thead>
<th>Object Name</th>
</thead>
<tbody></tbody>
</table>
it returns "cannot read property 'length' of undefined" javascript error..
Can you help ? Thank you