Hi,
For a webdatagrid that is in CellEditing behavior enabled,
How can i get to the collection of those rows that was edited from client side based on a button click? (I am looking to do some validations in client side)I am looking for something like the below:
var grid = $find("gridid");var gridBehaviors = grid.get_behaviors(); //get grid behaviorsvar gridEditBehaviors = gridBehaviors.get_editingCore().get_behaviors().get_cellEditing(); // get cell editing behavior// get the edited rows collection from the cell editing behavior (How to?)// iterate throw each rows from the rows collection and get to each cell value that got changed (how to?)
Our Server Side(Logic of setting grid in Cell Editing Mode):
grdDataTable.Behaviors.GetBehavior(Of EditingCore)().Enabled = TruegrdDataTable.Behaviors.GetBehavior(Of EditingCore)().EnableInheritance = TruegrdDataTable.Behaviors.GetBehavior(Of EditingCore)().AutoCRUD = FalsegrdDataTable.Behaviors.GetBehavior(Of EditingCore)().BatchUpdating = True
Dim _cellEditingBehavior As CellEditing = New CellEditing()
' Define and add the cell editing behavior_cellEditingBehavior.Enabled = True_cellEditingBehavior.EditModeActions.EnableOnActive = True_cellEditingBehavior.EditModeActions.MouseClick = EditMouseClickAction.Single
grdDataTable.Behaviors.GetBehavior(Of EditingCore)().Behaviors.Add(_cellEditingBehavior)
Thanks,Aravind
Hi Aravind,
First, you will need to manually save the column keys of the columns, whose cells were edited. This can happen in the ExitingEditMode or ExitedEditMode event:
function WebDataGrid1_CellEditing_ExitingEditMode(sender, eventArgs) { var columnKey = eventArgs.getCell().get_column().get_key(); if (editedColumnsKeys.indexOf(columnKey) == -1) { editedColumnsKeys.push(); } }
Then, you can access the collection of edited/deleted/added rows from the EditingCore behavior, and iterate over the cells using the keys from the collection:
var grid = $find("gridid"); var gridEditingCore = grid.get_behaviors().get_editingCore(); var editedRows = gridEditingCore.get_editedRows(); for (var i=0; i < editedRows.length; i++) { var editedRow = editedRows[i]; for (var y=0; y < editedColumnsKeys.ength; y++)) { var cellValue = editedRow.get_cellByColumnKey(editedColumnsKeys[y]).get_value(); } }
Please let me know if you have further questions, I will be glad to help.
Thanks Hristo, This helped!