Calling sendData from an event handler

In most of our operations on the grid, users have automated ways to update the columns. To handle this we turn off automated updates on DataProcessor so we can send the data when we know we are finished with the automatic changes. This works fine through a non event handler function.

dp.setUpdateMode("off");

In one case, when users edit a particular cell on the grid, I need to send the data for that row only. I am attaching an event handler to manage that.

Attaching the handler:

grid.attachEvent("onEditCell", applyCellOverride);

Handler function:

function applyCellOverride(stage, rowId, cellIndex, newValue, oldValue) {
  if (stage == 2 && cellIndex == 11) {
	var costCell = grid.cellById(rowId, 9);
	var rMarginCell = grid.cellById(rowId, cellIndex + 1);
	
	var cost = parseFloat(costCell.getValue());
	rMarginCell.setValue((((newValue - cost)/newValue) * 100).toFixed(2));
	
	dp.setUpdated(rowId, true);
	dp.sendData();
  }

  return true;
};

This mostly works. The correct data is sent to the server and the server sends back the results DataProcessor expects:

<?xml version="1.0" encoding="UTF-8"?>
<data>
  <action sid="219" tid="219" type="updated"/>
</data>

The only problem is it seems like DataProcessor never knows the results were returned. The changed row stays highlighted in bold. Should I be calling sendUpdate from somewhere other than the event handler?

Thanks.

After onEditCell finish, it will call dp.setUpdated(rowId, true); on its own ( because it always called after cell edit operation ) so you will have two updates one manual, second automatic, and while manual one will be sent to server , automatic will not be sent - which will result in marking row in bold , as saved and not updated.

To fix issue, you can replace

dp.setUpdated(rowId, true);
dp.sendData();

with

window.setTimeout(function(){ dp.sendData(); },1);

as result setUpdated will be called only once, automatically, and sendData will be called when edit process finished, and will send updated row to the server.

Hi Stanislav,

Thanks for the explanation of the cause of this and the fix. It worked perfectly.