mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
70038bfd5b
commit
5f767e2c9a
@ -35,7 +35,7 @@ export function getTextAlign(field?: Field): TextAlignProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getColumns(data: DataFrame, availableWidth: number, columnMinWidth: number): Column[] {
|
export function getColumns(data: DataFrame, availableWidth: number, columnMinWidth: number): Column[] {
|
||||||
const columns: Column[] = [];
|
const columns: any[] = [];
|
||||||
let fieldCountWithoutWidth = data.fields.length;
|
let fieldCountWithoutWidth = data.fields.length;
|
||||||
|
|
||||||
for (const [fieldIndex, field] of data.fields.entries()) {
|
for (const [fieldIndex, field] of data.fields.entries()) {
|
||||||
@ -50,6 +50,15 @@ export function getColumns(data: DataFrame, availableWidth: number, columnMinWid
|
|||||||
fieldCountWithoutWidth -= 1;
|
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);
|
const Cell = getCellComponent(fieldTableOptions.displayMode, field);
|
||||||
columns.push({
|
columns.push({
|
||||||
Cell,
|
Cell,
|
||||||
@ -58,6 +67,7 @@ export function getColumns(data: DataFrame, availableWidth: number, columnMinWid
|
|||||||
accessor: (row: any, i: number) => {
|
accessor: (row: any, i: number) => {
|
||||||
return field.values.get(i);
|
return field.values.get(i);
|
||||||
},
|
},
|
||||||
|
sortType: selectSortType(field.type),
|
||||||
width: fieldTableOptions.width,
|
width: fieldTableOptions.width,
|
||||||
minWidth: 50,
|
minWidth: 50,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user