JS Grid: OnCellEditCompleted event infinitely fired RRS feed

  • Question

  • Hi everyone,

    I am working on a pivoted grid webpart and I am making use of the JSGrid control. I have implemented a function in JS to handle the OnCellEditCompleted event, that will update some cells. The OnCellEditCompleted event SHOULD never fire programmatically (as mentioned in this article, but it is firing because of the cell update, I guess.

    This is a critical issue for my webpart, as it makes it very unstable, thus not suitable for production yet.

    I can't figure out any way to solve this issue, and I would be very grateful if someone could offer some help.

    Here's some code of the aforementioned webpart:

    In this block, I attach a method to the OnCellEditCompleted event:

    this.Init = function (jsGridControl, initialData, props) {
    	_jsGridControl = jsGridControl;
    	_props = props;
    	this.Properties = _props;
    	// This event is triggered after the standard grid error checking.
    	jsGridControl.AttachEvent(SP.JsGrid.EventType.OnCellEditCompleted, GridManager_OnCellEditCompleted);

    Here is my method that handles the event:

    function GridManager_OnCellEditCompleted(obj) {
    	// check the total rows
    	if ($.inArray(obj.recordKey, WGM.TotalRowsUIDs) == -1 && $.inArray(obj.recordKey, WGM.AvailabilityRowsUIDs) == -1) {
    		if (WGM.IsSaveProjectsEnabled()) {
    			var cachedRecord = _dataSource.tableCache.GetCachedRecord(obj.recordKey);
    			var value = cachedRecord.GetDataValue(obj.fieldKey);
    			if (obj.fieldKey.indexOf('RES_') != -1 && obj.fieldKey.indexOf('_TotalWork') != -1) {
    				if (value === undefined) value = 0;
    				UpdateTotal(obj.fieldKey, obj.recordKey, value);
    				UpdateAvailability(obj.fieldKey, obj.recordKey, value);
    				DisplayStatusInfo("Status: There are unsaved updates.");
    	} else {
    		obj.bCancelled = true;
    	return obj.bCancelled;
    The 'UpdateTotal' and 'UpdateAvailability' methods update cells in the grid. The OnCellEditCompleted event shouldn't be fired when modifying a cell programmatically (should be firing only when a user does that), but it is... Then, an infinite loop is going on, and eventually the execution is stopped when the call stack limit is reached (stack overflow).

    Please help! :)

    Thanks & Regards

    Wednesday, November 7, 2012 9:44 AM

All replies

  • I recall simillar problems from the past, even though I used the OnRecordChanged event. I solved this using a global variable to indicate that an 'initial' OnCellEditCompleted event is fired. In subsequent calls I than would skip the UpdateTotal and UpdateAvailability call. Likely you have to index your variable by the recordKey as your grid can contain multiple records. And finally you need to reset your variable at some point for which I trapped (from memory) the OnEntryRecordCommitted event.

    Jan Cirpka

    Wednesday, November 7, 2012 1:19 PM