从 v11.0.4 更新到 v11.1.5 后,ngx-datatable“无法读取 null 的属性‘长度’”

Tom*_*omP 1 ngx-datatable angular

将 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)
Run Code Online (Sandbox Code Playgroud)

我尝试降级到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'"
  >
Run Code Online (Sandbox Code Playgroud)

数据是异步的,因此表在 init 上没有数据。有任何想法吗?

小智 5

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