Example for DataTables edit delete add buttons in asp.NET MVC
Example for DataTables edit delete add buttons in asp.NET MVC
mindfreak93
Posts: 1Questions: 1Answers: 0
I searched in almost all the posts regarding this, but i don't get the expected result.
I would like to create in ASP.NET MVC the following table: https://editor.datatables.net/examples/styling/bootstrap.html
After a lot of modifications this is what i got:
` $(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: {
create: {
type: 'POST',
url: 'US/AddUS',
},
edit: {
type: 'PUT',
contentType: 'application/json',
url: 'US~~~~/Edit',
data: function (d) {
var newdata;
$.each(d.data, function (key, value) {
newdata = JSON.stringify(value);
console.log("ajax data new data...:" + newdata);
});
console.log("ajax data new data:" + newdata);
return newdata;
},
delete: {
type: 'DELETE',
url: 'US/Remove',
},
}
},
table: "#example",
fields: [{
label: "ID:",
name: "ID"
}, {
label: "Name:",
name: "Name"
}, {
label: "Active:",
name: "Active"
}
]
});
$('#example').dataTable({
dom: "Bfrtip",
ajax: {"url":"http://localhost:7837/US/DataHandler", "type" : "GET" },
columns: [
{
data: null,
defaultContent: '',
className: 'select-checkbox',
orderable: false
},
{ data: "ID" },
{ data: "Name" },
{ data: "Active" },
],
select: {
style: 'os',
selector: 'td:first-child'
},
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]
});
});`
Now when i access that page is giving me an error in DataTableEditor block: JavaScript runtime error: Object doesn't support this action
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Could you let me know which link of code in the above the error is pointing to please?
The only thing I immediately spot is the
delete
parameter inside theedit
object for Editor's Ajax configuration.Firstly it should be
remove
(seeajax
), and secondly it should be a child of theajax
option.Regards,
Allan