TablePanel: Sort numbers correctly (#25421)

* Table sortType to basic to be able to sort negative numbers

* Table sortType based on field type
This commit is contained in:
Speak Your Code 2020-06-08 14:28:45 +02:00 committed by GitHub
parent 70038bfd5b
commit 5f767e2c9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -35,7 +35,7 @@ export function getTextAlign(field?: Field): TextAlignProperty {
}
export function getColumns(data: DataFrame, availableWidth: number, columnMinWidth: number): Column[] {
const columns: Column[] = [];
const columns: any[] = [];
let fieldCountWithoutWidth = data.fields.length;
for (const [fieldIndex, field] of data.fields.entries()) {
@ -50,6 +50,15 @@ export function getColumns(data: DataFrame, availableWidth: number, columnMinWid
fieldCountWithoutWidth -= 1;
}
const selectSortType = (type: FieldType): string => {
switch (type) {
case FieldType.number:
case FieldType.time:
return 'basic';
default:
return 'alphanumeric';
}
};
const Cell = getCellComponent(fieldTableOptions.displayMode, field);
columns.push({
Cell,
@ -58,6 +67,7 @@ export function getColumns(data: DataFrame, availableWidth: number, columnMinWid
accessor: (row: any, i: number) => {
return field.values.get(i);
},
sortType: selectSortType(field.type),
width: fieldTableOptions.width,
minWidth: 50,
});