Save and restore collapsed groups (#20591)

This commit is contained in:
Bram Kragten
2024-04-23 21:00:17 +02:00
committed by GitHub
parent 7e25366897
commit 81922f5a3e
3 changed files with 25 additions and 1 deletions

View File

@@ -43,6 +43,10 @@ export interface SelectionChangedEvent {
value: string[];
}
export interface CollapsedChangedEvent {
value: string[];
}
export interface SortingChangedEvent {
column: string;
direction: SortingDirection;
@@ -139,6 +143,8 @@ export class HaDataTable extends LitElement {
@property() public sortDirection: SortingDirection = null;
@property({ attribute: false }) public initialCollapsedGroups?: string[];
@state() private _filterable = false;
@state() private _filter = "";
@@ -245,8 +251,12 @@ export class HaDataTable extends LitElement {
).length;
}
if (properties.has("groupColumn")) {
if (!this.hasUpdated && this.initialCollapsedGroups) {
this._collapsedGroups = this.initialCollapsedGroups;
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
} else if (properties.has("groupColumn")) {
this._collapsedGroups = [];
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
}
if (
@@ -723,6 +733,7 @@ export class HaDataTable extends LitElement {
} else {
this._collapsedGroups = [...this._collapsedGroups, groupName];
}
fireEvent(this, "collapsed-changed", { value: this._collapsedGroups });
};
static get styles(): CSSResultGroup {
@@ -1096,5 +1107,6 @@ declare global {
"selection-changed": SelectionChangedEvent;
"row-click": RowClickedEvent;
"sorting-changed": SortingChangedEvent;
"collapsed-changed": CollapsedChangedEvent;
}
}