Example for DataTables edit delete add buttons in asp.NET MVC

Example for DataTables edit delete add buttons in asp.NET MVC

mindfreak93mindfreak93 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

Answers

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    Answer ✓

    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 the edit object for Editor's Ajax configuration.

    Firstly it should be remove (see ajax), and secondly it should be a child of the ajax option.

    Regards,
    Allan

This discussion has been closed.