Why is data empty when deleting a table record
Why is data empty when deleting a table record

According the documentation for REST Interface, when deleting a record datatables editor will submit data as follows:
data[row_3][DT_RowId]=row_3
data[row_3][first_name]=Ashton
data[row_3][last_name]=Cox
data[row_3][position]=Junior Technical Author
data[row_3][email]=a.cox%40datatables.net
data[row_3][office]=San Francisco
data[row_3][extn]=1562
data[row_3][age]=66
data[row_3][salary]=86000
data[row_3][start_date]=2009-01-12
action=remove
However when I submit the data dictionary for Django REST Framework it is empty:
"data":{}
Here is my javascript:
<script type="text/javascript">
var editor;
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
table: "#object-table",
ajax: {
create: {
type: 'POST',
url: "{% url 'facility-list' format='datatables' %}",
headers: {'X-CSRFToken': '{{ csrf_token }}'}
},
edit: {
type: 'PUT',
url: "{% url 'facility-detail' pk=None format='datatables' %}",
headers: {'X-CSRFToken': '{{ csrf_token }}'}
},
remove: {
type: 'DELETE',
url: "{% url 'facility-detail' pk=None format='datatables' %}"
}
},
idSrc: 'bldgcode',
fields: [
{ label: "Building Code:", name: "bldgcode" },
{ label: "Name:", name: "name" },
{
label: "Category:",
name: "category",
type: "select",
options: []
},
{
label: "Location:",
name: "location",
type: "select",
options: []
}
],
i18n: {
create: {
button: "Add",
title: "Add new facility",
submit: "Add"
},
edit: {
button: "Edit",
title: "Edit facility details",
submit: "Update"
},
remove: {
button: "Delete",
title: "Delete facility",
submit: "Delete",
confirm: {
1: "Are you sure you want to delete the selected facility?"
}
}
}
} );
$.fn.dataTable.Buttons.defaults.dom.button.className = 'btn btn-sm btn-primary';
var table = $('#object-table').DataTable( {
pageLength: 10,
order: [[ 0, 'asc' ]],
processing: true,
serverSide: true,
dom: "lBfrtip",
ajax: "{% url 'facility-list' format='datatables' %}",
select: 'single',
columns: [
{ data: "bldgcode" },
{ data: "name" },
{ data: "category_label" },
{ data: "location_name" }
],
buttons: [
{ extend: "create", editor: editor},
{ extend: "edit", editor: editor},
{ extend: "remove", editor: editor}
]
});
table.buttons().container()
.appendTo($('.col-md-6:eq(0)', table.table().container()));
editor.field('category').input().addClass('form-control');
editor.field('location').input().addClass('form-control');
});
</script>
Any assistance would be greatly appreciated.
Thanks,
mgpearce48
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Have you verified what is in the XHR request headers using the browser's Developer Tools > Network tab?
When you say the
"data":{}
is submitted are you saying that is what your Django script receives from the client or what it sends back?Kevin
From the browser using the Developer Tools > Network tab > Body tab:
however I note from Developer Tools > Network tab > Parameters tab:
I'm not sure which one I'm supposed to be looking at?
Thanks,
mgpearce48
OK got it sorted. I was looking at the response instead of the request, and was able to retrieve the data via Django request.query_params instead of request.data.
Many thanks for your help.
Regards,
mgpearce48