【问题标题】:Refresh ngx-datatable headers刷新 ngx-datatable 标头
【发布时间】:2018-08-17 13:08:41
【问题描述】:

对于我正在构建的数据表,我需要使用动态标题(单击按钮时,不同的数据会加载到表中并且标题需要更改)。我正在使用它在软删除用户和普通用户之间切换(删除列变为恢复列)。

更新行,表格的工作方式如下所述: this.rows = [...this.rows];

更新我的专栏是另一回事。我使用this.columns = [...this.columns]; 以同样的方式尝试过,但这不会刷新表头。现在我所拥有的是一个表格,其中标题仅在后台刷新时才会更改,我似乎无法找到自己触发刷新的方法。我的桌子是这样的:

<ngx-datatable
  [rows]="rows"
  [columns]="columns"
  [columnMode]="'flex'"
  [sortType]="'single'"
  [headerHeight]="50"
  [footerHeight]="50"
  [selected]="selected"
  (select)='onSelect($event)'
  [selectionType]="'checkbox'"
  [selectAllRowsOnPage]="true"
  [limit]="rowLimit"
  [reorderable]="false"
  [rowHeight]="'auto'" style="width: 100%">
</ngx-datatable>

这是我更新列的代码:

this.route.params.subscribe(params => {
  this.state = params.state;

  if (this.state === 'deleted') {
    this.columns[columnIndex].name = 'Recover';
  } else if (this.state === 'notactivated') {
    this.columns[columnIndex].name = 'Delete';
  }

【问题讨论】:

    标签: angular ngx-datatable


    【解决方案1】:

    好的,我又花了几个小时,但我想通了。这有点老套,但如果我将列 ID 设置为未定义,我可以强制刷新列。下面的代码在每次更新列标题时都有效并强制刷新(我称之为switchedColumn):

    // If there is a switchedColumn, remove the old column and add this as a new column to force a refresh
    if (switchedColumn && switchedColumn.$$id) {
      this.columns = this.columns.filter(c => c.$$id != switchedColumn.$$id);
      switchedColumn.$$id = undefined;
      this.columns = [...this.columns, switchedColumn]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      相关资源
      最近更新 更多