mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Add option for custom group order to data table (#20582)
This commit is contained in:
parent
eb1354d229
commit
1b54d51e4a
@ -133,6 +133,8 @@ export class HaDataTable extends LitElement {
|
|||||||
|
|
||||||
@property() public groupColumn?: string;
|
@property() public groupColumn?: string;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public groupOrder?: string[];
|
||||||
|
|
||||||
@property() public sortColumn?: string;
|
@property() public sortColumn?: string;
|
||||||
|
|
||||||
@property() public sortDirection: SortingDirection = null;
|
@property() public sortDirection: SortingDirection = null;
|
||||||
@ -254,6 +256,7 @@ export class HaDataTable extends LitElement {
|
|||||||
properties.has("sortColumn") ||
|
properties.has("sortColumn") ||
|
||||||
properties.has("sortDirection") ||
|
properties.has("sortDirection") ||
|
||||||
properties.has("groupColumn") ||
|
properties.has("groupColumn") ||
|
||||||
|
properties.has("groupOrder") ||
|
||||||
properties.has("_collapsedGroups")
|
properties.has("_collapsedGroups")
|
||||||
) {
|
) {
|
||||||
this._sortFilterData();
|
this._sortFilterData();
|
||||||
@ -530,13 +533,24 @@ export class HaDataTable extends LitElement {
|
|||||||
const sorted: {
|
const sorted: {
|
||||||
[key: string]: DataTableRowData[];
|
[key: string]: DataTableRowData[];
|
||||||
} = Object.keys(grouped)
|
} = Object.keys(grouped)
|
||||||
.sort((a, b) =>
|
.sort((a, b) => {
|
||||||
stringCompare(
|
const orderA = this.groupOrder?.indexOf(a) ?? -1;
|
||||||
|
const orderB = this.groupOrder?.indexOf(b) ?? -1;
|
||||||
|
if (orderA !== orderB) {
|
||||||
|
if (orderA === -1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (orderB === -1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return orderA - orderB;
|
||||||
|
}
|
||||||
|
return stringCompare(
|
||||||
["", "-", "—"].includes(a) ? "zzz" : a,
|
["", "-", "—"].includes(a) ? "zzz" : a,
|
||||||
["", "-", "—"].includes(b) ? "zzz" : b,
|
["", "-", "—"].includes(b) ? "zzz" : b,
|
||||||
this.hass.locale.language
|
this.hass.locale.language
|
||||||
)
|
);
|
||||||
)
|
})
|
||||||
.reduce((obj, key) => {
|
.reduce((obj, key) => {
|
||||||
obj[key] = grouped[key];
|
obj[key] = grouped[key];
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -165,6 +165,8 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
|
|
||||||
@property() public initialGroupColumn?: string;
|
@property() public initialGroupColumn?: string;
|
||||||
|
|
||||||
|
@property({ attribute: false }) public groupOrder?: string[];
|
||||||
|
|
||||||
@state() private _sortColumn?: string;
|
@state() private _sortColumn?: string;
|
||||||
|
|
||||||
@state() private _sortDirection: SortingDirection = null;
|
@state() private _sortDirection: SortingDirection = null;
|
||||||
@ -422,6 +424,7 @@ export class HaTabsSubpageDataTable extends LitElement {
|
|||||||
.sortColumn=${this._sortColumn}
|
.sortColumn=${this._sortColumn}
|
||||||
.sortDirection=${this._sortDirection}
|
.sortDirection=${this._sortDirection}
|
||||||
.groupColumn=${this._groupColumn}
|
.groupColumn=${this._groupColumn}
|
||||||
|
.groupOrder=${this.groupOrder}
|
||||||
>
|
>
|
||||||
${!this.narrow
|
${!this.narrow
|
||||||
? html`
|
? html`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user