tonytomov / jqGrid

jQuery grid plugin
www.trirand.com
2.84k stars 1.2k forks source link

Cell editing with remote data and a low latency server does not update the table properly #1011

Open eCitiz opened 2 years ago

eCitiz commented 2 years ago

An example project can be found here : https://jsfiddle.net/nducoin/ue0kyxtz/4/

Editing multiple cells of a table with remote data does not work properly when the server does not respond quickly enough.

I noticed the following when sending multiple edit request on different cells before their processing by the server:

The editing of the same cell multiple times does not work properly either.

I managed to fix this bug in the version 5.5.4 by updating the "saveCell" function by using the parameter "iRow" instead of the value "$t.p.savedRow[fr].rowId" and by removing the right element in the "$t.p.savedRow" array:

...
// var trow = $($t).jqGrid("getGridRowById", $t.p.savedRow[0].rowId),
var trow = $($t).jqGrid("getGridRowById", iRow),
...
// postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, $t.p.savedRow[fr].rowId);
postdata[idname] = $.jgrid.stripPref($t.p.idPrefix, iRow);
...
$(cc).empty();
//$($t).jqGrid("setCell",$t.p.savedRow[fr].rowId, iCol, v2, false, false, true);
$($t).jqGrid("setCell",iRow, iCol, v2, false, false, true);
cc = $('td', trow).eq( iCol );
$(cc).addClass("dirty-cell");
$(trow).addClass("edited");
// $($t).triggerHandler("jqGridAfterSaveCell", [$t.p.savedRow[fr].rowId, nm, v, iRow, iCol]);
$($t).triggerHandler("jqGridAfterSaveCell", [iRow, nm, v, iRow, iCol]);
if ($.jgrid.isFunction($t.p.afterSaveCell)) {
    // $t.p.afterSaveCell.call($t, $t.p.savedRow[fr].rowId, nm, v, iRow,iCol);
    $t.p.afterSaveCell.call($t, iRow, nm, v, iRow,iCol);
}
// Adding a processing for removing the right element in the array "$t.p.savedRow"
var indexOfSavedRowBeingProcessed = -1;
for (var savedRowIterator of $t.p.savedRow)
{
    if (savedRowIterator.rowId == iRow && savedRowIterator.ic == iCol)
    {
        indexOfSavedRowBeingProcessed = $t.p.savedRow.indexOf(savedRowIterator);
    }
}
if (indexOfSavedRowBeingProcessed !== -1) 
{
    $t.p.savedRow.splice(indexOfSavedRowBeingProcessed, 1);
}
// $t.p.savedRow.splice(0,1);
...
tonytomov commented 2 years ago

Hello,

Apologize for the late answer. The problem lie in the how the ajax is using. We use ajax complete instead of success which causes this delay. We plan to rewrite this code to use ajax success, but this is not a trivial task, because of the existing users.

Using the iRow in place of rowId is not a good solution for all existing users.

Best Regards

eCitiz commented 8 months ago

Hello,

Do you know when this problem could be fixed?

Best regards

tonytomov commented 8 months ago

Hello I have fixed the problem. Fortunately the success contain [jqXHR] object too. See here: https://github.com/tonytomov/jqGrid/commit/67f46f5a37616ff47bf6887114d8b5dbfc17641d

Please test the fix and let me if it is ok for you.