Sort battery level column using numeric sort (#14926)

fixes undefined
This commit is contained in:
karwosts 2023-01-23 12:10:01 -08:00 committed by GitHub
parent 81e4f083f9
commit e242fbe148
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -200,7 +200,6 @@ export class HaDataTable extends LitElement {
Object.values(clonedColumns).forEach(
(column: ClonedDataTableColumnData) => {
delete column.title;
delete column.type;
delete column.template;
}
);

View File

@ -55,12 +55,17 @@ const sortData = (
? b[column.valueColumn || sortColumn][column.filterKey]
: b[column.valueColumn || sortColumn];
if (column.type === "numeric") {
valA = isNaN(valA) ? undefined : Number(valA);
valB = isNaN(valB) ? undefined : Number(valB);
} else {
if (typeof valA === "string") {
valA = valA.toUpperCase();
}
if (typeof valB === "string") {
valB = valB.toUpperCase();
}
}
// Ensure "undefined" is always sorted to the bottom
if (valA === undefined && valB !== undefined) {