ParamQuery grid support forum
General Category => ParamQuery Pro Evaluation Support => Topic started by: rpcosta on March 03, 2016, 09:29:33 pm
-
Hello everyone,
I'm trying to create a function for validation of a select columns to prevent the user from selecting options that have already been selected in other rows. I've managed to get it to work for new rows using getData. But if I edit a row and don't change it this doesn't work as the getData returns the values of all rows (including the one I'm editing) and as so detects the value is already being used and won't save.
Is there a way to get the data from all the rows except the one I'm editing? Or get number of the row I'm editing so I can exclude it from the array that getData returns?
I'll leave my code below so you can take a look.
Thanks in advance.
validations: [
{ type: function (ui) {
var value = ui.value;
var values = $grid.pqGrid("getData", { dataIndx: [ui.column.dataIndx] } );
for (i = 0; i < values.length; i++) {
if(values[i][ui.column.dataIndx] == value) {
ui.msg = "Duplicate entry";
return false;
}
}
}
}
]
-
rowIndx & rowData are not available from getData()
so option( "dataModel.data" ) can be used in which case values[ i ] points to rowData and if values[ i ] == ui.rowData, then it means current row.
var values = $grid.pqGrid( "option", "dataModel.data" );
if( (values[ i ][ ui.dataIndx ] == value) && (values[ i ] != ui.rowData) ) {
ui.msg = "Duplicate entry";
return false;
}