<button ejs-button (click)='handleClick($event)'>Clear Data</button>
<ejs-grid [dataSource]='data' (cellSave)="onsave($event)" [editSettings]='editSettings' [toolbar]='toolbar' [height]='150'>
<e-columns>
<e-column field='OrderID' headerText='ID' isPrimaryKey='true' width=150></e-column>
<e-column field='FoodName' headerText='Food Name' width=150></e-column>
<e-column field='Protein' headerText='Protein' textAlign='Right' width=120></e-column>
<e-column field='Fat' headerText='Fat' textAlign='Right' width=80></e-column>
<e-column field='Carbohydrate' headerText='Carbohydrate' textAlign='Right' width=120></e-column>
<e-column headerText='Calories Intake' textAlign='Right' [valueAccessor]='totalCalories' width=150></e-column>
</e-columns>
</ejs-grid>
…………………………………….
public totalCalories = (field: string, data: { Protein: number, Fat: number, Carbohydrate: number }, column: Object): number => {
return data.Protein * 4 + data.Fat * 4 + data.Carbohydrate * 9;
}
|
public data: Object[];
public editSettings: Object;
public toolbar: string[];
public pageSettings: Object;
ngOnInit(): void {
this.editSettings = { allowEditing: true, allowAdding: true, allowDeleting: true };
this.toolbar = ['Add', 'Edit', 'Delete', 'Update', 'Cancel'];
//Grid dataSource.
this.data = [
{ OrderID: 10248, FoodName: 'VINET', Protein: 1, Fat:20,Carbohydrate: 33.38,ShipName:'Alfreds Futterkiste',ShipCountry:'Brazil'},
{ OrderID: 10249, FoodName: 'TOMSP', Protein: 2, Fat:15,Carbohydrate: 11.61,ShipName:'Ana Trujillo Emparedados y helados',ShipCountry:'France'},
];;
this.pageSettings = { pageCount: 5 };
}
………………………………….
handleClick(){
this.data = []; // remove the dataSource on button click, it will be refelected in grid. not need to refredh the Grid.
}
|
[app.component.ts]
handleClick(){
var tdata = this.data.slice(0) // create a new list
tdata[0]["OrderID"]=101; // Apply the changes in clone array list
this.data = tdata; // Replace this.data value by tdata
}
|