My Html:
ejs-grid #grid [dataSource] = 'data' [editSettings] = 'editSettings' [toolbar] = 'toolbar' height = '273px' [(selectedItem)] = "recordSelezionato">
<E-columns>
<e-column field = 'CustomerID' headerText = 'Customer ID' width = 120> </ e-column>
<e-column field = 'Quantity' headerText = 'Quantity' editType = 'numericity' [edit] = 'totalParams' width = 150> </ e-column>
<e-column field = 'Price' headerText = 'Price' editType = 'numericity' [edit] = 'totalParams' width = 150> </ e-column>
<e-column field = 'Total' headerText = 'Total' textAlign = 'Right' editType = 'numericity' [edit] = 'totalParams' width = 120 format = 'C2'> </ e-column>
</ E-columns>
</ Ejs-grid>
My Ts:
public recordSelezionato: CorpoDocumento;
ngOnInit (): void {
this.data = data;
this.editSettings = {allowEditing: true, allowAdding: true, allowDeleting: true};
this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
this.totalParams = {params: {change: this.totaliRiga.bind (this)}};
}
totaliRiga (args) {
recordSelezionato.Total = recordSelezionato.Price * recordSelezionato,Quantity
}
so automatically the html also updates me.
|
@Component({
selector: 'app-container',
template: `<ejs-grid #grid [dataSource]='data' [editSettings]='editSettings'[toolbar]='toolbar' height='273px'>
<e-columns>
. . . . .
</e-columns>
</ejs-grid>`
})
export class AppComponent implements OnInit {
. . . . . .
priceUpdate(args){
let quantity=this.grid.element.querySelector('#'+ this.grid.element.id + 'Quantity').value;
let price=edit.querySelector('#'+ this.grid.element.id + 'Price').ej2_instances[0];
price.value = args.value / quantity; // calculate price value
}
totalUpdate(args){
let quantity=this.grid.element.querySelector('#'+ this.grid.element.id + args ).value; let total=this.grid.element.querySelector('#'+ this.grid.element.id + 'Total').ej2_instances[0];
total.value = arguments[1].value * quantity; // calculate total value
}
ngOnInit(): void {
. . . . .
this.totalParams = { params: {change: this. priceUpdate.bind(this) } };
this.priceParams = { params: {change: this. totalUpdate.bind(this, ‘Quantity’) } };
this.quantityParams = { params: {change: this. totalUpdate.bind(this, ’Price’) } };
}
} |