Editor - How to switch from remove to edit mode on the fly and update value

Editor - How to switch from remove to edit mode on the fly and update value

CapamaniaCapamania Posts: 233Questions: 81Answers: 5

I have an inline remove and a select remove (for multiple records) to remove records. Removing records works fine (also editing as standalone).

In some instances instead of "removing" a or multiple record(s), I want to 'update' a value in one flow. I've tried to change the .mode() and .set() the value, but I'm getting and error: Uncaught TypeError: d is undefined

How can I achieve the desired workflow?

// "Delete" record inline:
var delete_groups_inline = $('#groups').on('click', 'a.remove_groups', function (e) {
    e.preventDefault();
    var removeRow = $(this).closest('tr');
    editor_groups.remove( removeRow, {
        title: 'Remove Record',
        message: 'Are you sure you want to remove this record?',
        buttons: [{
            label: 'Delete',
            fn: function () { this.submit(); }
        }]
    })
    .mode('edit')
    .set( 'groups.status', 2 );
});


// "Delete" selected record(s):
{
    extend: "remove",
    editor: editor_groups,
    text: 'Delete selected',
    action: function ( e, dt, node, config ) {
        var rows = table_groups.rows( '.selected' );
        var rowIndexes = rows.indexes();
        editor_groups.remove( rowIndexes, {
            title: 'Remove Record',
            message: 'Are you sure you want to remove this record?',
            buttons: [{
                label: 'Delete',
                fn: function () { this.submit(); }
            }]
        })
        .mode('edit')
        .set( 'groups.status', 2 );
    }
}   

Error in both instances:

Uncaught TypeError: d is undefined
multiGet http://127.0.0.1/js/libs/dataTables.editor.min.js:24
_submit http://127.0.0.1/js/libs/dataTables.editor.min.js:99
each jQuery
_submit http://127.0.0.1/js/libs/dataTables.editor.min.js:99
each jQuery
_submit http://127.0.0.1/js/libs/dataTables.editor.min.js:99

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    Changing from remove to edit modes I think is unlikely to work, since the edit action is very different from delete.

    Rather than calling remove() first, can you not just call edit() in those two cases? You know you are going to make it an edit, so why call remove() first? You can still use title and message to indicate that it is a (soft) delete action and hide the field inputs.

    See this example which does this.

    Allan

  • CapamaniaCapamania Posts: 233Questions: 81Answers: 5

    Great, thanks!

Sign In or Register to comment.