// Can use one duplicationRules function for all column field?
<ColumnDirective field='OrderID' headerText='Order ID' validationRules={this.duplicationRules} width='100' textAlign="Right" isPrimaryKey={true}/>
<ColumnDirective field='CustomerID' defaultValue='HANAR' validationRules={this.duplicationRules} headerText='Customer ID' width='120'/>
[index.js]
actionBegin(args) {
if (args.requestType === 'save' && args.action == "add") {
var isExist = this.gridInstance.dataSource.some(row=> row.OrderID == args.data.OrderID)
if(isExist){
args.cancel =true;
var editform = this.gridInstance.getContentTable().querySelector(".e-row.e-addedrow");
editform.remove();
this.gridInstance.refresh();
}
}
}
|
[index.js]
export class NormalEdit extends SampleBase {
constructor() {
super(...arguments);
. . . .
this.validationRule = { required: [this.commonCustomFN.bind(this),"Please enter CustomerName"] };
this.orderidRules = { required: [this.commonCustomFN.bind(this),"Please enter OrderID"]};
}
commonCustomFN(args){
switch (args.element.name) {
case "OrderID":
if (args.value == "") {
return false
} else { return true }
break;
case "CustomerName":
if (args.value == "") {
return false
} else { return true }
}
}
<GridComponent dataSource={orderDataSource} ref={grid => this.gridInstance = grid} toolbar={this.toolbarOptions} allowPaging={true} editSettings={this.editSettings} pageSettings={this.pageSettings} actionBegin={this.actionBegin.bind(this)}>
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='Order ID' width='140' textAlign='Right' validationRules={this.orderidRules} isPrimaryKey={true}></ColumnDirective>
<ColumnDirective field='CustomerName' headerText='Customer Name' width='150' validationRules={this.validationRule}></ColumnDirective>
. . . .
</ColumnsDirective>
<Inject services={[Page, Toolbar, Edit]}/>
</GridComponent>
|
actionBegin(args) {
if (args.requestType === 'save' && args.action == "add") {
var isExist = this.gridInstance.dataSource.some(row=> row.OrderID == args.data.OrderID)
var isDuplicate = this.gridInstance.dataSource.some((data)=>{
return Object.entries(data).toString() === Object.entries(args.data).toString();
})
if(isDuplicate){
args.cancel =true;
var editform = this.gridInstance.getContentTable().querySelector(".e-row.e-addedrow");
editform.remove();
this.gridInstance.refresh();
}
}
}
|
[index.js]
actionBegin(args) {
if (args.requestType === 'save' && args.action == "add") {
var isExist = this.gridInstance.dataSource.some(row => row.OrderID == args.data.OrderID)
var isDuplicate = this.gridInstance.dataSource.some((data) => {
return Object.entries(data).toString() === Object.entries(args.data).toString();
})
if (isDuplicate) {
args.cancel = true;
var editform = this.gridInstance.getContentTable().querySelector(".e-row.e-addedrow");
editform.remove();
this.gridInstance.refresh();
}
}
if (args.requestType === 'save') {
var columns = DataUtil.distinct(this.gridInstance.columns, "field", false);
var obj = {}
columns.forEach((col) => {
if (args.data[col] != args.rowData[col]) {
obj[col] = args.data[col]
}
})
var key = Object.keys(obj);
var hasDuplicate = false;
if (key.length > 0) {
hasDuplicate = this.gridInstance.dataSource.some((item) => item[key] === obj[key])
}
if (hasDuplicate) {
args.cancel = true;
var editform;
if(args.action == "edit") {
editform = this.gridInstance.getContentTable().querySelector(".e-row.e-editedrow");
} else if(args.action="add"){
editform =this.gridInstance.getContentTable().querySelector(".e-row.e-addedrow");
}
editform.remove();
this.gridInstance.refresh();
}
}
}
|