Export (0) Print
Expand All

add_commitCellEditing(function)

apps for Office and SharePoint

Last modified: October 03, 2012

Applies to: apps for SharePoint | Excel Services | SharePoint Server 2013

In this article
Return Value
Remarks
Example

Subscribes an event handler to the [commitCellEditing] event.

Ewa.EwaControl.add_commitCellEditing(function);

function

The event handler to subscribe to the event.

The Ewa.EwaControl.add_commitCellEditing method subscribes an event handler to the commitCellEditing event. The commitCellEditing event fires when the focus is moved from the cell being edited to another cell or range; that is, when the user has committed the cell edit by moving to a new cell or range.

When the specified event handler for the commitCellEditing event is invoked, it is invoked with a single argument of type Ewa.RangeEditEventArgs. You use the Ewa.RangeEditEventArgs to get references to other objects related to a given instance of the commitCellEditing event, and to get data, including the value of the cell before editing and the value after editing the cell. Additionally, the Ewa.RangeEditEventArgs provides the setTargetUnformattedValue method that you can use to set a value in the cell that is being edited.

The following code example subscribes an event handler to the commitCellEditing event. The code also shows how to use the Ewa.RangeEditEventArgs to get information about the specified range. The code example assumes that you are working with an Excel Web Access Web Part on SharePoint Server 2013.

<script type="text/javascript">
var ewa = null;

// Add event handler for onload event.
if (window.attachEvent) {
    window.attachEvent("onload", ewaOnPageLoad);
}
else {
    window.addEventListener("DOMContentLoaded", ewaOnPageLoad, false);
}

function ewaOnPageLoad() {
    if (typeof (Ewa) != "undefined") {
        Ewa.EwaControl.add_applicationReady(ewaApplicationReady);
    }
    else {
        alert("Error - the EWA JS is not loaded.");
    }
    // ...
}

function ewaApplicationReady() {
    // Get a reference to the Excel Services Web Part.
    ewa = Ewa.EwaControl.getInstances().getItem(0);
    // Add an event handler for the 
    // active cell changed event.
    ewa.add_commitCellEditing(ewaCommitCellEditing);

    // ...
}

function ewaCommitCellEditing(rangeEditArgs) {
    // Get the value of the cell before editing
    var oldValue = rangeEditArgs.getTargetOldUnformattedValue();
    // Get the value of the cell after editing
    var newValue = rangeEditArgs.getTargetUnformattedValue();

    // Display the before and after values of the cell
    alert("Old value: " + oldValue.toString() + "\nNew value: " + newValue.toString());

    var o = "Set via code";

    // Set the value of the cell via code
    rangeEditArgs.setTargetUnformattedValue(o);
} // End ewaCommitCellEditing
</script>

Show:
© 2014 Microsoft