Hi,
In the event CellValueChanging (EditingCore EditingClientEvents-CellValueChanging and EditingClientEvents CellValueChanging), I want to verify if the user is entering a value that is already in the same column of the same group of child rows (child rows Under the same parent wor) or the parents rows, depending if he is changing the value for a child row or a parent row. If the value already exist, i want to cancel the CellValueChanging event (i already do it for other reasons in the same event, for example if value >= 900). This works already for any other validations when the user enters a value in an existing row or a new row as parent row or child row (i didn't have to iterate the other rows yet). I just can't iterate the throught the rows of the same group of rows and get the other values of the column to compare them with the value the user has just entered in the cell. Is there a way to do it and cancel the event (or at least not add this value in the grid because it can be saved in the database on postback)?
Thank you.
I have even tried with the selected row but i cant get the first selected row as usual to get its grid to iterate rows when i'm in CellValueChanging.
var selectedRows = grid.get_gridView().get_behaviors().get_selection().get_selectedRows(); //works
var selectedRow0 = selectedRows.getItem(0); //doesn't work
Hello Danjut,
Thank you for contacting Infragistics Developer Support!
You can use the sender argument from your handler for CellValueChanging which will be the grid and cancel the event.
function WebHierarchicalDataGrid_Editing_CellValueChanging(sender, eventArgs) { var cellNewValue = eventArgs.get_newValue(); var columnKey = eventArgs.get_cell().get_column().get_key() if (isCellAlreadyInGrid(cellNewValue, columnKey, sender)) { eventArgs.set_cancel(true); } } function isCellAlreadyInGrid(cellNewValue, columnKey, grid) { var rows = grid.get_rows(); for (var i = 0; i < rows.get_length(); i++) { var row = grid.get_rows().get_row(i); var cell = row.get_cellByColumnKey(columnKey); if (cellNewValue == cell.get_value()) { alert(cellNewValue + " already exists!"); return true; } } return false; }
Let me know if you need further assistance.
Hello danjut,
The code that Denis has shared should iterate through the rows in the same RowIsland that the cell you are trying to edit is.
I believe that this would be sufficient for your needs.
Do you need any other assistance?
My colleague found that the Owner property returns the GridView/RowIsland also. So i'll test his information and your answer. Thank you very much. Here is my colleague example to know how many rows are in my current row's gridView:
eventArgs.get_cell().get_row()._get_owner().get_rows().get_length()
Looking forward for hearing from you.
Because i'm kinda out-of-time, i just tested your solution and it works for all my needs, just as you said. I didn't took time to test my colleague's solution so if anyone has some time to test it (not tested for new added rows by my colleague), please tell us if it works. Thank you everyone!
The snippet I've provided works for adding new rows also.