ASPxClientGridViewBatchEditApi.SetCellValueByKey(key, columnFieldNameOrId, value) Method
Assigns a new value to the specified cell in batch edit mode.
Declaration
SetCellValueByKey(
key: any,
columnFieldNameOrId: string,
value: any,
displayText?: string,
cancelCellHighlighting?: boolean
): void
Parameters
Name | Type | Description |
---|---|---|
key | any | The key value of the row that contains the processed cell. |
columnFieldNameOrId | string | The field name or unique identifier (the Name property value) of the column that contains the processed cell. |
value | any | The new cell value. |
displayText | string | The cell display text. |
cancelCellHighlighting | boolean |
|
Remarks
Call the SetCellValueByKey
method to assign a new value to the cell specified by the row’s key value.
// Sets a new value to the specified cell
clientGrid.batchEditApi.SetCellValueByKey(rowKey, 'ContactName', 'New customer');
// Sets a new value to the specified cell and disables its highlighting
clientGrid.batchEditApi.SetCellValueByKey(rowKey, 'ContactName', 'New customer', null, false)
This method is not in effect in the following cases:
- The column’s Visible property is set to
false
. - The specified cell is in edit mode.
Add a New Row and Specify Its Cell Values
When you call the AddNewRow method to create a new row, the grid switches to edit mode. The code sample below gets the key value of the inserted row (the key property) and ends cell editing (the EndEdit method) to allow the grid to assign new values to the cells within the inserted row.
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" KeyFieldName="CustomerID"
ClientInstanceName="clientGrid">
<Columns>
<dx:GridViewDataTextColumn FieldName="ContactName" />
<%--...--%>
</Columns>
<SettingsEditing Mode="Batch" />
</dx:ASPxGridView>
<dx:ASPxButton ID="ASPxButton1" runat="server" Text="Add New Row" AutoPostBack="false">
<ClientSideEvents Click="OnButtonClick" />
</dx:ASPxButton>
function OnButtonClick(s, e) {
clientGrid.batchEditApi.AddNewRow();
var rowKey = clientGrid.batchEditApi.GetEditCellInfo().key;
clientGrid.batchEditApi.EndEdit();
clientGrid.batchEditApi.SetCellValueByKey(rowKey, 'ContactName', 'New customer');
}