Cancel preremove event

Cancel preremove event

alexschalexsch Posts: 3Questions: 1Answers: 0

Hi all,

I want to cancel a preremove event in case an integrity check fails.

Following the approach described in https://datatables.net/forums/discussion/43689 I tried to return false to cancel the preRemove event but it does not work:

Editor.on('preRemove', function (e, json) {
            let canContinue = true;
            $.each(data, function(index, rowId) {
                canContinue = checkCanContinue(rowId);
            });
            if(!canContinue) {
                alert('In Use.')
                return false;
            }
        });

Any ideas?

Answers

  • tangerinetangerine Posts: 3,350Questions: 37Answers: 394

    Your alert statement needs a semi-colon.

  • alexschalexsch Posts: 3Questions: 1Answers: 0

    Sorry, the semi-colon missed the copy & paste somehow. Nevertheless the event does not get cancelled and the row is removed.

  • alexschalexsch Posts: 3Questions: 1Answers: 0

    Seems that not all pre* events can be cancelled by returning false.

    This works:

    editor.on('preOpen', function (e, mode, action) {
                if(action == 'remove') {
                    let canContinue = true;
    
                    table.rows( { selected: true } ).ids().each(function(rowId) {
                        if(false == doIntegrityCheck(rowId)) {
                            canContinue = false;
                            ingredientsTable.buttons.info(
                                'Warning',
                                'Cannot delete row',
                                3000
                            );
                            return;
                        }
                    });
    
                    return canContinue;
                }
            });
    
This discussion has been closed.