组件属性改变时不调用cellClass
函数
如何踢rowClass
或cellClass
?
@Component({
...,
template: `<ngx-datatable [rowClass]="rowClass"></ngx-datatable>`
})
class SomeComponent {
someVariable = true;
rowClass = (row) => {
return {
'some-class': (() => { return this.someVariable === row.someVariable })()
};
}
}
相关https://github.com/swimlane/ngx-datatable/issues/774
我可以通过改变this.rows
来解决这个问题。
https://swimlane.gitbook.io/ngx-datatable/cd
this.rows = [...this.rows];
如果您正在使用存储,则需要取消不可变属性。
例子@Input() set list(list: Record<string, unknown>[]) {
if (list.length) {
// If the search results are reflected in the table.
// And 20 items are loaded at a time.
if (list.length === 20) {
this.rows = list.map((item) => ({ ...item }));
// Load more items
} else {
const newRows = list.map((item) => ({ ...item })).slice(this.rows.length);
this.rows = this.rows.concat(newRows);
}
}
}