volosoft / jtable

A JQuery plugin to create AJAX based CRUD tables.
http://www.jtable.org
1.1k stars 506 forks source link

Calling deleteRecord on selectedRows doesn't always delete the row from the jtable #2242

Closed MikeAllred closed 4 years ago

MikeAllred commented 4 years ago

jQuery 1.11.2 jTable 2.4.0

Scenario: In our application, we are selecting multiple documents (rows) in jTable and then "archiving" them. Upon successful "archiving" of each document, we call deleteRecord to remove the row from the jTable. Sometimes this works and all rows are removed (normally dependent on how many rows are selected), but most of the time with more documents selected for archiving, we see one or more (but normally no more that a couple) that are still selected or still present in the jTable. The "archiving" action is done via an async Ajax call and does complete successfully, but the resulting call to deleteRecord either doesn't appear to be getting issued or it's failing b/c the row is still present in the table.

Any thoughts/suggestions? Below is a code snippet of the relevant calls

var $myElems = $('#fullGrid').jtable('selectedRows');
if($myElems.length > 1) {
    $myElems.each(function () {
        $elem=$(this);
        dhAjax.run({
            type: "POST",
            async: true,
            url: <this call to server does all the archiving stuff>,
            success: function() {
                var key = $elem[0].getAttribute('data-record-key');
                var record = $('#fullGrid').jtable('getRowByKey', key)
                $('#fullGrid').jtable('deleteRecord',
                    {       
                        clientOnly: true,
                        key: key
                });
            }
        })
    })
}
dasguptahirak commented 4 years ago

have you tried using this in ajax success event $('#fullGrid').jtable('reload');

MikeAllred commented 4 years ago

I had not tried that... i added it after the call to deleteRecord.... It appears to be working (obviously) as i haven't had the "straggler" rows since the update.

Thanks for the suggestion