【问题标题】:ngx-datatable - Returning Empty Table (Angular 6)ngx-datatable - 返回空表(Angular 6)
【发布时间】:2018-11-20 23:06:03
【问题描述】:

我正在尝试通过 API 响应(异步函数)填充 ngx 数据表。我已经设法让这些功能正常工作,但是表中的行是空白的(创建了正确的行数)。

当我将鼠标悬停在桌子上时,正如预期的那样,它会触发 onActivate 函数来记录事件,当我查看事件数据时,我可以看到要显示在桌子上的数据。这表明数据准确地传递到表,但问题是由于排序的呈现问题。

HTML:

<div class="row">
    <div class="col-sm-12">
        <ngx-datatable class="bootstrap selection-cell"
          [rows]="rows"
          [columnMode]="'force'"
          [columns]="columns"
          [headerHeight]="50"
          [footerHeight]="50"
          [rowHeight]="'auto'"
          [limit]="20"
          [selected]="selected"
          [selectionType]="'multiClick'"
          (activate)="onActivate($event)"
          (select)='onSelect($event)'>
        </ngx-datatable>
    </div>
</div>

组件:

res_out = {}
  res_out_ = []
  rows = []
  loadingIndicator = true;
  reorderable = true;
  selected = [];

  columns = [
    { name: 'ID'},
    { name: 'FileID'},
    { name: 'SectionNum'}
  ];

  constructor() {

      this.fetchData((dt) => {
        this.rows = dt;
        setTimeout(() => { this.loadingIndicator = false; }, 1500);
      });

    };


  async fetchData(cb) {
    return await API.get(this.apiName, this.path, this.myInit).then(response => {
      response.forEach(element => {
        this.columns.forEach((el, i) => this.res_out[el.name] = element[i]);
        this.res_out_.push(this.res_out)
      });
      console.log(this.res_out_)
       cb(this.res_out_)
    }).catch(error => {
      this.res_out_ = [this.res_out]
      console.log(error.response)

    });
  }

我尝试通过 Observable 填充数据,但异步管道仍然不起作用。

有什么想法吗?

【问题讨论】:

  • 你能展示你尝试了什么吗?编辑并将您的源代码包含在问题中。
  • 刚刚添加了您要求的代码位。

标签: angular angular6 ngx-datatable


【解决方案1】:

将“prop”定义添加到您的列定义中以绑定到属性

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多