@Component({
selector: 'control-content',
template: ' <ejs-grid [dataSource]='data' height='350' (queryCellInfo)='customiseCell($event)'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right'></e-column>
<e-column field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right'></e-column>
. . .
</e-columns>
</ejs-grid>'
})
export class DefaultComponent implements OnInit {
public data: Object[] = [];
ngOnInit(): void {
this.data = orderDetails;
}
customiseCell(args: QueryCellInfoEventArgs) {
if (args.column.field === 'Freight') {
if (args.data['Freight'] < 30) {
args.cell.classList.add('below-30');
} else if (args.data['Freight'] < 80) {
args.cell.classList.add('below-80');
} else {
args.cell.classList.add('above-80');
}
}
}
} |
<style>
.below-30 {
background-color: orangered;
}
.below-80 {
background-color: yellow;
}
.above-80 {
background-color: greenyellow;
}
</style> |
customiseCell(args: QueryCellInfoEventArgs) {
if (args.column.field === 'Freight') {
if (args.data['Freight'] < 80) {
args.cell.style.backgroundColor ="greenyellow" ; // setting style directly
}
}
} |