【问题标题】:How to change color of row based on particular column condition in kendo grid for angular如何根据剑道网格中的特定列条件更改行的颜色以获取角度
【发布时间】:2019-06-30 09:29:27
【问题描述】:

我想将红色应用于已完成小时数列值大于 24 的行。我该怎么做。请帮助我是角度的新手。

<kendo-grid [kendoGridBinding]="gridData">
    <kendo-grid-column field="RequestNumber" title="Request No."  
width="110" >
    </kendo-grid-column>
<kendo-grid-column field="RequestNumber" title="Request No."  width="110" >
    </kendo-grid-column>
<kendo-grid-column field="Name" title="Name."  width="110" >
    </kendo-grid-column>
<kendo-grid-column field="CompletedIn" title="CompletedIn"  width="110" >
    </kendo-grid-column>
 </kendo-grid>

【问题讨论】:

标签: angular kendo-ui kendo-grid kendo-angular-ui


【解决方案1】:

首先:您必须将[rowClass] 添加到您的网格中

<kend-grid [rowClass]="rowCallback">
</kendo-grid>

那么你需要在组件内部添加函数并返回需要的类

public rowCallback(context: RowClassArgs) {
  if (context.dataItem.someProperty) {   // change this condition as you need
    return {
      passive: true
    };
  }
}  

最后,你需要一个 CSS 类,其名称与你返回的名称相同,(在本例中为 passive,当然你可以随意更改)

@Component({
  selector: "your-component",
  templateUrl: "./your.component.html",
  encapsulation: ViewEncapsulation.None,
  styles: [
    `
     .k-grid tr.passive {
        background-color: lightgray;
      }

    `
  ]
})

非常重要使用encapsulation: ViewEncapsulation.None并使用前缀.k-grid tr命名类,否则您将无法获得所需的结果

【讨论】:

    【解决方案2】:

    使用 rowClass 回调为所有数据项满足某些自定义条件的行提供自定义类,然后通过 CSS 设置它们的样式,例如:

    DOCS + DEMO

    【讨论】:

      【解决方案3】:

      如果满足上述条件,这将用红色背景颜色标记行

      <tr *ngFor="let myObject of myArray;" [ngStyle]="{'background-color':myObj.completedIn>24 ? 'red' : '' }">
         <!-- your other code -->
      </tr>

      【讨论】:

      • 谢谢你的回答。实际上我使用的是剑道网格所以没有 标签
      猜你喜欢
      • 1970-01-01
      • 2016-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      • 2018-10-05
      相关资源
      最近更新 更多