diff --git a/packages/grafana-ui/src/components/Table/Table.tsx b/packages/grafana-ui/src/components/Table/Table.tsx index ae75fec6e9c..e81678d2669 100644 --- a/packages/grafana-ui/src/components/Table/Table.tsx +++ b/packages/grafana-ui/src/components/Table/Table.tsx @@ -25,7 +25,7 @@ import { import { TableCellBuilder, ColumnStyle, - getCellBuilder, + getFieldCellBuilder, TableCellBuilderOptions, simpleCellBuilder, } from './TableCellBuilder'; @@ -153,7 +153,7 @@ export class Table extends Component { return { header: title, width: columnWidth, - builder: getCellBuilder(col.config || {}, style, this.props), + builder: getFieldCellBuilder(col, style, this.props), }; }); } diff --git a/packages/grafana-ui/src/components/Table/TableCellBuilder.tsx b/packages/grafana-ui/src/components/Table/TableCellBuilder.tsx index 70e37babda3..08473bad2f1 100644 --- a/packages/grafana-ui/src/components/Table/TableCellBuilder.tsx +++ b/packages/grafana-ui/src/components/Table/TableCellBuilder.tsx @@ -291,3 +291,33 @@ class CellBuilderWithStyle { return simpleCellBuilder({ value, props, className }); }; } + +export function getFieldCellBuilder(field: Field, style: ColumnStyle | null, p: Props): TableCellBuilder { + if (!field.display) { + return getCellBuilder(field.config || {}, style, p); + } + + return (cell: TableCellBuilderOptions) => { + const { props } = cell; + const disp = field.display!(cell.value); + + let style = props.style; + if (disp.color) { + style = { + ...props.style, + background: disp.color, + }; + } + + let clazz = 'gf-table-cell'; + if (cell.className) { + clazz += ' ' + cell.className; + } + + return ( +
+ {disp.text} +
+ ); + }; +}