[英]Kendo Grid Angular 6 Add class conditinoally in column
I have below link. 我有下面的链接。
https://stackblitz.com/edit/angular-pwq1rq-d4ymup?file=app/app.component.ts https://stackblitz.com/edit/angular-pwq1rq-d4ymup?file=app/app.component.ts
import { Component } from '@angular/core';
import { Component, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'my-app',
encapsulation: ViewEncapsulation.None,
styles: [`
tr .myClass {
color: green
}
`],
template: `
<kendo-grid [data]="gridData" style="height: 200px">
<kendo-grid-column field="ProductName" title="Product Name" width="200" [class]="{'myClass': 1 > 0}">
</kendo-grid-column>
<kendo-grid-column field="UnitPrice" title="Unit Price" width="230" [class]="{'myClass': check(UnitPrice) }">
</kendo-grid-column>
</kendo-grid>
`
})
export class AppComponent {
public gridData: any[];
constructor() {
this.gridData = [{
"ProductID": 1,
"ProductName": "Chai",
"UnitPrice": 18,
"Discontinued": true
}, {
"ProductID": 2,
"ProductName": "Chang",
"UnitPrice": 10,
"Discontinued": false
}];
}
check(d:any){
console.log(d)
if( d > 10)
return true
else
return false
}
}
Need to add class on condition, also Unable to find how to add else part there 需要根据条件添加类,也无法找到如何在其中添加其他部分
Thanks 谢谢
You can add class conditionally using [ngClass]. 您可以使用[ngClass]有条件地添加类。 Here's the example: 例子如下:
<some-element [ngClass]="{'first': true, 'second': true, 'third': false}">...</some-element>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.