我正在使用DataTable和Editor,我想检查column_02中是否已存在特定值,但仅针对column_01中具有特定值的行。更具体,例如我想检查value_04是否在column_02中,但仅用于column_01中的1行。如果该值已存在,则应显示错误消息。
column_01 | column_02
1,value_03
1,value_02
1,value_01
3,value_01
5,value_04
下面检查该值是否在整个column_02中(但不依赖于column_01中的值):
editor_table.on( 'preSubmit', function ( e, o, action ) {
if ( action !== 'remove' ) {
var getcolumn_01 = editor_table.field( 'table.column_01' );
var getcolumn_02 = editor_table.field( 'table.column_02' );
var indexcolumn_01 = table_table.column( 0 ).data().indexOf(getcolumn_01.val());
var indexcolumn_02 = table_table.column( 1 ).data().indexOf(getcolumn_02.val());
if ( ! getcolumn_02.isMultiValue() ) {
if ( indexcolumn_02 >= 0 ) {
getcolumn_02.error( 'Name selected already exist in Busket!' );
}
}
// If any error was reported, cancel the submission so it can be corrected
if ( this.inError() ) {
return false;
}
}
} );
// console.log(getcolumn_01); = 1
// console.log(getcolumn_02); = value_04