Using DataTables with Django - No matching records found error

Using DataTables with Django - No matching records found error

ccphantomccphantom Posts: 2Questions: 1Answers: 0
edited April 2017 in Free community support

Hi experts,
I use DataTables server-side function to render my large data, according to the Official Manual, I return the json object that contain "recordsTotal","recordsFiltered","data" successfully. But the page display "No matching records found".

I use dataFilter function to capture the data from server-side, the code is:
''' var result_table = $('#result_table').DataTable( {
"processing": true,
"serverSide": true,
"deferRender": true,
"ajax": {
"url":"{% url 'business_packages:products_list' %}",
"type":"POST",
"dataSrc": "",
dataFilter: function (data) {
var json = jQuery.parseJSON(data);
json.recordsTotal = json.recordsTotal;
json.recordsFiltered = json.recordsFiltered;
json.data = jQuery.parseJSON(json.data);
//return json;
//return JSON.stringify(json.data); //return JSON string
return JSON.stringify(json);
}
},
"columns":[
{ "data": "fields.name" },
{ "data": "fields.category" },
{ "data": "fields.units_per_cost" },
{ "data": "fields.min_price" },
{ "data": "fields.retail_price" },
{ "data": "fields.max_price" },
],
"scrollX": true,
"scrollY": "60vh",
},
} );'''

Please see the attached to see the returned data from server-side.

BTW, if I change the code "return JSON.stringify(json)" to "return JSON.stringify(json.data)", it can display data successfully, but at this way, I cann't pass the parameters "recordsTotal", "recordsFiltered" to client side.

Any help is appreciate, Thanks advance.

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.