tonytomov / jqGrid

jQuery grid plugin

Home Page:www.trirand.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

eCitiz opened this issue · comments

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 requests received by the server are corrupts: The "id" is always the same when editing different cells and the "value" is not always the right value
  • The processing of the server's response does not update the right cell with the right value: the first cell edited is cleared and the following cells are either cleared or display a wrong value

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);
...

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

Hello,

Do you know when this problem could be fixed?

Best regards

Hello I have fixed the problem. Fortunately the success contain [jqXHR] object too.
See here: 67f46f5

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