Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update grid header and footer on column tree update #6648

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions packages/grid/src/vaadin-grid-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ export const GridMixin = (superClass) =>
this.__updateFooterPositioning();
this.generateCellClassNames();
this.generateCellPartNames();
this.__updateHeaderAndFooter();
}

/** @private */
Expand Down Expand Up @@ -1001,19 +1002,22 @@ export const GridMixin = (superClass) =>
* It is not guaranteed that the update happens immediately (synchronously) after it is requested.
*/
requestContentUpdate() {
if (this._columnTree) {
// Header and footer renderers
this._columnTree.forEach((level) => {
level.forEach((column) => {
if (column._renderHeaderAndFooter) {
column._renderHeaderAndFooter();
}
});
});
// Header and footer renderers
this.__updateHeaderAndFooter();

// Body and row details renderers
this.__updateVisibleRows();
}
// Body and row details renderers
this.__updateVisibleRows();
}

/** @private */
__updateHeaderAndFooter() {
(this._columnTree || []).forEach((level) => {
level.forEach((column) => {
if (column._renderHeaderAndFooter) {
column._renderHeaderAndFooter();
}
});
});
}

/** @protected */
Expand Down
49 changes: 48 additions & 1 deletion packages/grid/test/renderers.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from '@esm-bundle/chai';
import { fixtureSync, isIOS, keyDownOn } from '@vaadin/testing-helpers';
import { fixtureSync, isIOS, keyDownOn, nextFrame } from '@vaadin/testing-helpers';
import sinon from 'sinon';
import { flushGrid, getBodyCellContent, getCell, getContainerCell } from './helpers.js';

Expand Down Expand Up @@ -248,6 +248,53 @@ describe('renderers', () => {

expect(headerCell._content.textContent).to.be.empty;
});

it('should apply an update to hidden column header', async () => {
// Hide the column
column.hidden = true;
// Change the renderer
column.headerRenderer = (root) => {
root.textContent = 'foo';
};
await nextFrame();
// Unhide the column
column.hidden = false;
await nextFrame();

// Expect the header to be updated
expect(headerCell._content.textContent).to.eql('foo');
});

it('should apply updates to hidden column headers', async () => {
// Add another column
const newColumn = document.createElement('vaadin-grid-column');
newColumn.headerRenderer = (root) => {
root.textContent = 'header2';
};
grid.appendChild(newColumn);

// Hide both columns
column.hidden = true;
newColumn.hidden = true;

// Change the renderer of both columns
column.headerRenderer = (root) => {
root.textContent = 'foo';
};
newColumn.headerRenderer = (root) => {
root.textContent = 'bar';
};
await nextFrame();

// Unhide both columns
column.hidden = false;
newColumn.hidden = false;
await nextFrame();

// Expect both headers to be updated
expect(headerCell._content.textContent).to.eql('foo');
expect(getHeaderCell(grid, 1)._content.textContent).to.eql('bar');
});
});

describe('footer cell', () => {
Expand Down