Possible to soft delete

Possible to soft delete

randy.johnsonrandy.johnson Posts: 18Questions: 8Answers: 0

Hello,

Is it possible to do a soft delete with the php library?

Thanks!

Randy

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    You mean like what Laravel lets you do? Instead of deleting the row, just set the deleted_on column to the date, then exclude any rows with that column as populated?

    I dont believe so, at least not right out of the box.. But you can obviously edit the PHP file to do it. Thats all Open Source.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    jLinux is correct - although there isn't a trivial option to do this, it is relatively straight forward to setup a method to do it. The way I would suggest doing it myself is to create a custom button that will use the Editor API (edit(), set() and submit()) to edit the selected rows, setting their delete flag to 1 (or whatever you use to mark a row as deleted) and then submit that to the server.

    Simply apply a where condition to then load only the rows which are not marked as deleted.

    Allan

  • robgeorgeukrobgeorgeuk Posts: 3Questions: 2Answers: 0

    The below worked for me.

    Using the simple example (https://editor.datatables.net/examples/simple/simple.html) I added the below JS

    editor
                .on( 'preSubmit', function ( e, o, a ) {
                    if (a == 'remove') {
                        o.action = "edit"; // Change action from delete to edit
    
                        // Loop through selected records and set deleted value
                        for (var key in o.data) {
                            if (o.data.hasOwnProperty(key)) {
                                o.data[key].deleted = 1;
                            }
                        }
                    }
                } );
    

    On the PHP side, I also added the 'deleted' field to the Editor instance. e.g.

    Field::inst( 'deleted')
    

    Hope that helps someone.

This discussion has been closed.