我的 Angular 2 应用程序中有一个 primeng 数据表 (1.1.0),我正在使用 rowStyleClass 将类设置为展开的行。
问题是,当行被扩展时,它工作正常,但如果我折叠它,那么它仍然与扩展类一起使用。
组件
rowStyle(rowData: any, rowIndex: number): string {
if ((this as DataTable).isRowExpanded(rowData)) {
return 'ui-state-highlight';
} else {
return '';
}
}
查看
<p-dataTable tableStyleClass="table" *ngIf="model.result.length > 0" [rows]="itemsPerPage" [paginator]="isPaginatorVisible()"
(onSort)="resetPagination()" [value]="xModel.ergebnis" [(selection)]="selected" expandableRows="true" [rowStyleClass]="rowStyle">
...
如果展开行:
<tr class="ui-datatable-even ui-datatable-odd ui-state-highlight ui-widget-content" ng-reflect-klass="ui-widget-content ui-state-highlight" ng-reflect-ng-class="[object Object]">
然后崩溃了:
<tr class="ui-datatable-even ui-datatable-odd ui-widget-content ui-state-highlight" ng-reflect-klass="ui-widget-content" ng-reflect-ng-class="[object Object]">
如您所见,ui-state-highlight 仅从 ng-reflect-klass 中删除,而没有从类本身中删除。是错误还是我做错了什么?
最佳答案
尝试手动检测更改并在更改后更新 View - 使用 Angular 更改检测:
import {ChangeDetectorRef} from '@angular/core';
constructor(private changeDetectorRef: ChangeDetectorRef) {}
rowStyle(rowData: any, rowIndex: number): string {
if ((this as DataTable).isRowExpanded(rowData)) {
return 'ui-state-highlight';
} else {
return '';
}
if (!this.changeDetectorRef['destroyed']) {
this.changeDetectorRef.detectChanges();
}
}
关于angular - primeng rowStyleClass 不能按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41168011/