TableNG: Support custom cell renderer (#103560)

* chore: support custom cells

* chore: fix types
pull/103655/head
Alex Spencer 1 month ago committed by GitHub
parent eeb4c045d3
commit 365bd2b208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      packages/grafana-ui/src/components/Table/TableNG/Cells/TableCellNG.tsx
  2. 9
      packages/grafana-ui/src/components/Table/TableNG/types.ts

@ -8,7 +8,13 @@ import { useStyles2 } from '../../../../themes';
import { t } from '../../../../utils/i18n';
import { IconButton } from '../../../IconButton/IconButton';
import { TableCellInspectorMode } from '../../TableCellInspector';
import { CellColors, FILTER_FOR_OPERATOR, FILTER_OUT_OPERATOR, TableCellNGProps } from '../types';
import {
CellColors,
CustomCellRendererProps,
FILTER_FOR_OPERATOR,
FILTER_OUT_OPERATOR,
TableCellNGProps,
} from '../types';
import { getCellColors, getTextAlign } from '../utils';
import { ActionsCell } from './ActionsCell';
@ -125,6 +131,10 @@ export function TableCellNG(props: TableCellNGProps) {
case TableCellDisplayMode.Actions:
cell = <ActionsCell actions={actions} />;
break;
case TableCellDisplayMode.Custom:
const CustomCellComponent: React.ComponentType<CustomCellRendererProps> = cellOptions.cellComponent;
cell = <CustomCellComponent field={field} value={value} rowIndex={rowIdx} frame={frame} />;
break;
case TableCellDisplayMode.Auto:
default:
cell = (

@ -81,6 +81,15 @@ export interface TableRow {
[columnName: string]: TableCellValue;
}
export interface CustomCellRendererProps {
field: Field;
rowIndex: number;
frame: DataFrame;
// Would be great to have generic type for this but that would need having a generic DataFrame type where the field
// types could be propagated here.
value: unknown;
}
export interface CustomHeaderRendererProps {
field: Field;
defaultContent: React.ReactNode;

Loading…
Cancel
Save