Skip to content

fix: do not throw error when adding a new row while a column is hidden - #2144

Merged
sosa-vaadin merged 2 commits into
masterfrom
fix/2136
Mar 12, 2021
Merged

sosa-vaadin merged 2 commits into
masterfrom
fix/2136

Conversation

@sosa-vaadin

@sosa-vaadin sosa-vaadin commented Mar 10, 2021 •

Copy link
Copy Markdown
Contributor

Fixes #2136.

A hidden column removes all of it cells from the DOM.

cell._content.parentNode.removeChild(cell._content);

All columns's _setBodyTemplateOrRenderer() method are called when the _cells property changes (e.g.: a new row is added).

'_setBodyTemplateOrRenderer(_bodyTemplate, renderer, _cells, _cells.*)',

This in turn calls the column's __setColumnTemplateOrRenderer() method and here, for each cell in the column, the grid's __getRowModel() method is called with the cell's parent (i.e.: the tr element, obtained with cell.parentElement)

__setColumnTemplateOrRenderer(template, renderer, cells) {
if (template && renderer) {
throw new Error('You should only use either a renderer or a template');
}
cells.forEach((cell) => {
const model = this._grid.__getRowModel(cell.parentElement);

However, since the cells of a hidden column were removed from the DOM, their parentElement is null, thus throwing an error when trying to access any of its properties in the grid's __getRowModel() method.

__getRowModel(row) {
return {
index: row.index,
item: row._item,
level: this._getIndexLevel(row.index),
expanded: this._isExpanded(row._item),
selected: this._isSelected(row._item),
detailsOpened: !!(this._rowDetailsTemplate || this.rowDetailsRenderer) && this._isDetailsOpened(row._item)
};
}

Just added an extra check to make sure the __setColumnTemplateOrRenderer() only gets called from the _setBodyTemplateOrRenderer() method if the column is not hidden i.e.: visible.

@CLAassistant

CLAassistant commented Mar 10, 2021 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sosa-vaadin
sosa-vaadin requested a review from yuriy-fix March 10, 2021 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Client-side exception thrown when hiding column, add item, and refresh data provider

3 participants