如何在NGX数据表中动态设置行类?

时间:2018-08-07 06:58:28

标签: javascript angular ngx-datatable

我基本上正在实现表外部的搜索功能,并且如果搜索内容与表行中的内容匹配,则希望突出显示行。 页面上也有多个表。

这是我的面板组件。

<app-mystuff-dashboard-panel *ngFor="let group of initialGroupedSearchResults | objectFilter: { MyContentSetScope: 'Private', MyContentSetType : 'System', contentSetName: 'Clipboard' } | orderBy: 'contentSetName'"
                                   [contentSet]="group"
                                   [searchText]="searchText"></app-mystuff-dashboard-panel>

在上述组件中,我正在运行ngOnChanges,以获取searchText更改(它是一个字符串)

我曾尝试在可ngx输入的输入中使用[rowClass] =“ getRowClass”,但是该函数不会总是触发,就像ngClass函数在每次更改时都会更改一样。

getRowClass(row) {
    return _includes(row.DynamicProperties.myContentItemKey, this.searchText) ? 'yellowbackground' : 'bluebackground';
  }

此函数中的row参数大部分是未定义的。另外,我在3个表上大约有100行,当searchText更改时,此getRowClass函数仅对3个表触发5次左右。

我尝试重新渲染onChange上的表,但效果也不佳。

if ((changes.searchText && (changes.searchText.currentValue !== changes.searchText.previousValue))) {
      console.log(this.searchText);
      this.items = this.items.slice();
      this.items = [...this.items];
      this.items.push({});
      this.items.splice(-1, 1);1

      this.items = [...this.items];
      this.changeDetector.detectChanges();
    }

0 个答案:

没有答案
相关问题