Author Topic: column validation unique select  (Read 3451 times)

rpcosta

  • Newbie
  • *
  • Posts: 2
    • View Profile
column validation unique select
« 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.

Code: [Select]
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;
}
}
}
}
]

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: column validation unique select
« Reply #1 on: March 04, 2016, 12:33:11 am »
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.

Code: [Select]
var values = $grid.pqGrid( "option", "dataModel.data" );

if( (values[ i ][ ui.dataIndx ] == value) && (values[ i ] != ui.rowData) ) {
ui.msg = "Duplicate entry";
        return false;
}
« Last Edit: March 04, 2016, 12:32:11 pm by paramquery »