In table control soft delete

In table control soft delete

equinox22equinox22 Posts: 17Questions: 5Answers: 0

Hi,

I'm trying to implement the soft delete as part of the in table form controls. I've tried to adapt the code given for soft delete into the in table controls but no joy so far.

    // Delete a record
    $('#cylinderTable').on('click', 'td.editor-delete', function (e, dt, node, config) {
        e.preventDefault();
        
        var row = table.row
        
                    editor
                        .hide( editor.fields() )
                        .one( 'close', function () {
                            setTimeout( function () { // Wait for animation
                                editor.show( editor.fields() );
                            }, 500 );
                        } )
                        .edit( rows, {
                            title: 'Cylinder Returned',
                            message: 'Are you sure you wish to mark this cylinder record as returned?',
                            buttons: 'Yes'
                        } )
                        .val( 'cylinders.returned', (new Date()).toISOString().split('T')[0] );
                }); 

This gives me 'Uncaught ReferenceError: table is not defined' at var row = table.row. What would be the best way of implementing soft delete inline?

Is there also a way to allow the table to display the soft deleted records if a checkbox is marked aswell?

Thanks

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,997Questions: 87Answers: 421

    I guess you are refering to this post:
    https://editor.datatables.net/examples/api/softDelete

    This gives me 'Uncaught ReferenceError: table is not defined' at var row = table.row.

    And yes: I don't see any data table definition in the code you posted ...

    Can you please read the forum rules on how to ask for help? Many thanks.

  • equinox22equinox22 Posts: 17Questions: 5Answers: 0

    I've managed to get this working by substituting table.row for $(this).closest('tr'); and this now works.

    So the code now looks like this - I've provided a comment on the soft delete example page with example code.

        // Delete a record
        $('#cylinderTable').on('click', 'td.editor-delete', function (e, dt, node, config) {
            e.preventDefault();
            
            var row = $(this).closest('tr');
            
                        editor
                            .hide( editor.fields() )
                            .one( 'close', function () {
                                setTimeout( function () { // Wait for animation
                                    editor.show( editor.fields() );
                                }, 500 );
                            } )
                            .edit( row, {
                                title: 'Cylinder Returned',
                                message: 'Are you sure you wish to mark this cylinder record as returned?',
                                buttons: 'Yes'
                            } )
                            .val( 'cylinders.returned', (new Date()).toISOString().split('T')[0] );
                    });
    

    I did try to create a test case but I couldn't get the buttons to appear after a few attempts.

    Are you able to provide any advice on how to get the hidden rows to appear when needed please?

    Thanks

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi,

    Thanks for the update - good to hear you found a solution for your use case.

    If you want the soft deleted rows to appear, you need to update the query at the server-side to not filter them out. In the PHP script you will see:

    ->where( 'users.removed_date', null )
    

    That needs to be removed if you want to see the soft deleted rows. You could do that by having a button that will add a parameter to the data sent to the server as part of the Ajax request (ajax.data / preXhr) that would trigger a condition to not add that part of the query.

    What would be cool would be to include that field in the returned data to the client-side and have it check if the row was soft deleted or not. If it was, add a class to the row (rowCallback) which will fade it out a bit (opacity: 0.5 perhaps).

    Allan

  • equinox22equinox22 Posts: 17Questions: 5Answers: 0

    Hi Allan,

    Thanks for the suggestion.
    I ended up going for the searchBuilder with predefined criteria. This will probably work better in the long term as it's quite a big table with a lot of rows. It also allows people to see all that have been removed seperately and then all that haven't and all without any conditions, so will help with accessibility.

    I do have another table in the works that is much smaller so will put your suggestion to use there.

    Thanks.

Sign In or Register to comment.