mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 10:46:35 +00:00
Make sure unhidden columns are put at the correct place (#21262)
This commit is contained in:
parent
2b5fba4a30
commit
37af77dabe
@ -202,20 +202,53 @@ export class DialogDataTableSettings extends LitElement {
|
|||||||
const columns = this._sortedColumns(
|
const columns = this._sortedColumns(
|
||||||
this._params.columns,
|
this._params.columns,
|
||||||
this._columnOrder,
|
this._columnOrder,
|
||||||
this._hiddenColumns
|
hidden
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!this._columnOrder) {
|
if (!this._columnOrder) {
|
||||||
this._columnOrder = columns.map((col) => col.key);
|
this._columnOrder = columns.map((col) => col.key);
|
||||||
} else {
|
} else {
|
||||||
|
const newOrder = this._columnOrder.filter((col) => col !== column);
|
||||||
|
|
||||||
|
// Array.findLastIndex when supported or core-js polyfill
|
||||||
|
const findLastIndex = (
|
||||||
|
arr: Array<any>,
|
||||||
|
fn: (item: any, index: number, arr: Array<any>) => boolean
|
||||||
|
) => {
|
||||||
|
for (let i = arr.length - 1; i >= 0; i--) {
|
||||||
|
if (fn(arr[i], i, arr)) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
let lastMoveable = findLastIndex(
|
||||||
|
newOrder,
|
||||||
|
(col) =>
|
||||||
|
col !== column &&
|
||||||
|
!hidden.includes(col) &&
|
||||||
|
!this._params!.columns[col].main &&
|
||||||
|
this._params!.columns[col].moveable !== false
|
||||||
|
);
|
||||||
|
|
||||||
|
if (lastMoveable === -1) {
|
||||||
|
lastMoveable = newOrder.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
columns.forEach((col) => {
|
columns.forEach((col) => {
|
||||||
if (!this._columnOrder!.includes(col.key)) {
|
if (!newOrder.includes(col.key)) {
|
||||||
this._columnOrder!.push(col.key);
|
if (col.moveable === false) {
|
||||||
|
newOrder.unshift(col.key);
|
||||||
|
} else {
|
||||||
|
newOrder.splice(lastMoveable + 1, 0, col.key);
|
||||||
|
}
|
||||||
|
|
||||||
if (col.defaultHidden) {
|
if (col.defaultHidden) {
|
||||||
hidden.push(col.key);
|
hidden.push(col.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._columnOrder = newOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._hiddenColumns = hidden;
|
this._hiddenColumns = hidden;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user