TableNG: Support custom cell renderer (#103560)
* chore: support custom cells * chore: fix types
This commit is contained in:
@@ -8,7 +8,13 @@ import { useStyles2 } from '../../../../themes';
|
|||||||
import { t } from '../../../../utils/i18n';
|
import { t } from '../../../../utils/i18n';
|
||||||
import { IconButton } from '../../../IconButton/IconButton';
|
import { IconButton } from '../../../IconButton/IconButton';
|
||||||
import { TableCellInspectorMode } from '../../TableCellInspector';
|
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 { getCellColors, getTextAlign } from '../utils';
|
||||||
|
|
||||||
import { ActionsCell } from './ActionsCell';
|
import { ActionsCell } from './ActionsCell';
|
||||||
@@ -125,6 +131,10 @@ export function TableCellNG(props: TableCellNGProps) {
|
|||||||
case TableCellDisplayMode.Actions:
|
case TableCellDisplayMode.Actions:
|
||||||
cell = <ActionsCell actions={actions} />;
|
cell = <ActionsCell actions={actions} />;
|
||||||
break;
|
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:
|
case TableCellDisplayMode.Auto:
|
||||||
default:
|
default:
|
||||||
cell = (
|
cell = (
|
||||||
|
|||||||
@@ -81,6 +81,15 @@ export interface TableRow {
|
|||||||
[columnName: string]: TableCellValue;
|
[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 {
|
export interface CustomHeaderRendererProps {
|
||||||
field: Field;
|
field: Field;
|
||||||
defaultContent: React.ReactNode;
|
defaultContent: React.ReactNode;
|
||||||
|
|||||||
Reference in New Issue
Block a user