2016-12-15 166 views
3

我在我的角2应用程序中有一个primeng数据表(1.1.0),我使用rowStyleClass将类设置为展开的行。primeng 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中移除,而不能从类本身移除。这是一个错误还是我做错了什么?

+0

是否有人有一个想法? – user3287019

+0

看起来你正在做的是正确的,而且这个功能已经被破坏了。 collapseRow选项也不提供解决方案。这张票提出了一个hacky的CSS解决方法:https://github.com/primefaces/primeng/issues/1845'p-datatable tbody> tr:not(.ui-widget-content)' –

+0

尝试手动检测更改并更新视图,改变之后 - 用Angular的ChnageDetector: 'if(!this.changeDetectorRef ['destroyed']){ this.changeDetectorRef.detectChanges(); }' –

回答

0

尝试手动发现变化和更新,查看,更改后 - 有角的ChnageDetector:

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(); 
    } 
    }