0

将 ngx-datatable 从 升级v11.0.4到后v11.1.5,出现错误。

 ERROR TypeError: Cannot read property 'length' of null
    at DatatableComponent.get [as allRowsSelected] (index.js:4867)
    at Object.eval [as updateDirectives] (DatatableComponent.html:18)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:14689)
    at checkAndUpdateView (core.js:13836)
    at callViewAction (core.js:14187)
    at execEmbeddedViewsAction (core.js:14145)
    at checkAndUpdateView (core.js:13837)
    at callViewAction (core.js:14187)
    at execComponentViewsAction (core.js:14119)
    at checkAndUpdateView (core.js:13842)

我试图降级v11.1.0但同样的问题。我的表定义如下所示:

 <ngx-datatable
  fxFlexFill
  #table
  class="material striped"
  [rows]="rows | async"
  [columnMode]="'force'"
  [scrollbarV]="true"
  [scrollbarH]="true"
  [headerHeight]="headerHeight"
  [footerHeight]="50"
  [rowHeight]="rowHeight"
  (scroll)="onScroll($event)"
  [selectionType]="'single'"
  >

数据是异步的,因此表在初始化时没有数据。有任何想法吗?

4

1 回答 1

4

您已经定义了“selectionType”,因此您需要在数据表和组件代码中定义“selected”。Datatable 脚本尝试从选定行中查找 selected.length 或其他相关字段,因此会出现该错误。添加[selected]="selected"到您的模板并添加selected = [];到您的 ts 文件中。它必须工作。

于 2018-11-29T14:29:09.230 回答