Hi – I am using Ignite UI with anguar 2 and typescript. I need my custom validator to do the following:
- The validator fires with the user moves away from the cell after typing a new value
- The new cell value is passed on to the custom validator
- I need to know the column and the row for the cell that has changed
- Validation: for the same row, check the new value typed by the user is equal or greater than the value in the same row but the previous column to the one firing the validator
This is what I have so far, but I do not know how to get hold of the row, column.
gridData.columnDefs.filter(cd => cd.key !== 'blah')
.map(cd => {
let cs = {
columnKey: cd.key,
editorType: 'numeric',
validation: true,
editorOptions: {
type: 'numeric',
// Must set max decimals so they're not rounded up to 0
maxDecimals: 5,
allowNullValue: true,
revertIfNotValid: false,
validatorOptions: {
// Value can be left null
required: false,
onblur: true,
onsubmit: true,
onchange: false,
valueRange: {
min: 0,
errorMessage: 'Value cannot be negative'
},
custom: function (value, fieldOptions) {
// How do I get hold of the row and column for the changed cell?
I have tried jQuery('#' + gridId).igGrid('activeRow'); but it doesn’t work
Thanks
Hello,
Is this code only firing after the user has clicked away from the cell? If so, the editCellEnded event can be handled to obtain a reference of the row and column by using ui.rowID and ui.columnKey and saved to a variable that can be accessed from the event and the custom function.
In pseudocode it would look like this:
var editedCellRowID, editedCellColumnKey;
//Within the grid instantiation
editCellEnded: function(evt, ui){
editedCellRowID = ui.rowID;
editedCellColumnKey = ui.columnKey
}
//We can now access the edited row within our custom function
console.log(editedCellRowID)
console.log(editedCellColumnKey)
Let me know if you have questions.
Hi - thank you. This has worked for me
Glad to hear it helped.
Let me know if you have any questions related to this issue.