Skip to content

bug(mat-table): Material Table tries to render rows on reorder when rows are not exists #30795

Closed
@lopatnov

Description

@lopatnov

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

When columns in mat-table re-order by moveItemInArray and dataSource is loading, so it's undefined, the error is happened in table.mjs, in _getAllRenderRows function in this lines of code:

// For each data object, get the list of rows that should be rendered, represented by the
// respective `RenderRow` object which is the pair of `data` and `CdkRowDef`.
for (let i = 0; i < this._data.length; i++) {

Because this._data is undefined.
The error is: TypeError: Cannot read properties of undefined (reading 'length')

Reproduction

StackBlitz link: not ready
Steps to reproduce:

  1. Configure <mat-table> tag with cdkDropList cdkDropListOrientation="horizontal" attribute
  2. Configure columns <mat-header-cell> tag with cdkDrag attribute
  3. Make some time for loading dataSource and update columns order by moveItemInArray function
  4. You should see an error in provided code of mat-table

Expected Behavior

Expected that mat-table should work normally with undefined dataSource. If source is empty, no rows exists, it's simple. Why I need to write some workaround like <mat-table [dataSource]="dataSource || []"? It's one of weakness of mat-table. And I think while data didn't load, it shouldn't start to render rows.

Actual Behavior

mat-table tries to render undefined rows, so error happened. After this error mat-table work in unexpected way. For example becomes something wrong with fixed columns. They became hidden one by one.

Environment

  • Angular: 19.1.0

  • CDK/Material: 19.1.0

  • Browser(s): Chrome Version 134.0.6998.178 (Official Build) (64-bit)

  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 11

  • "@angular/cdk": "^19.1.0",

  • "@angular/common": "^19.1.1",

  • "@angular/compiler": "^19.1.1",

  • "@angular/core": "^19.1.1",

  • "@angular/forms": "^19.1.1",

  • "@angular/material": "^19.1.0",

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/table

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions