diff --git a/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx b/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx index f71d2b9ec6326..19315b5835d5f 100644 --- a/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx +++ b/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.test.tsx @@ -508,6 +508,52 @@ describe('DatatableComponent', () => { }); }); + test('it detect last_value filtered metric type', () => { + const { data, args } = sampleArgs(); + + const table = data.tables.l1; + const column = table.columns[1]; + + column.meta = { + ...column.meta, + field: undefined, + type: 'number', + sourceParams: { ...column.meta.sourceParams, type: 'filtered_metric' }, + }; + table.rows[0].b = 'Hello'; + + const wrapper = shallow( + ({ convert: (x) => x } as IFieldFormat)} + dispatchEvent={onDispatchEvent} + getType={jest.fn()} + renderMode="view" + paletteService={chartPluginMock.createPaletteRegistry()} + uiSettings={{ get: jest.fn() } as unknown as IUiSettingsClient} + /> + ); + + expect(wrapper.find(DataContext.Provider).prop('value').alignments).toEqual({ + // set via args + a: 'center', + // default for string + b: 'left', + // default for number + c: 'right', + }); + }); + test('it should refresh the table header when the datatable data changes', () => { const { data, args } = sampleArgs(); diff --git a/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.tsx b/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.tsx index 6635ada9a4036..7ceffcaaff5db 100644 --- a/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.tsx +++ b/x-pack/plugins/lens/public/datatable_visualization/components/table_basic.tsx @@ -212,7 +212,14 @@ export const DatatableComponent = (props: DatatableRenderProps) => { const isNumericMap: Record = useMemo(() => { const numericMap: Record = {}; for (const column of firstLocalTable.columns) { - numericMap[column.id] = column.meta.type === 'number'; + // filtered metrics result as "number" type, but have no field + numericMap[column.id] = + (column.meta.type === 'number' && column.meta.field != null) || + // as fallback check the first available value type + // mind here: date can be seen as numbers, to carefully check that is a filtered metric + (column.meta.field == null && + typeof firstLocalTable.rows.find((row) => row[column.id] != null)?.[column.id] === + 'number'); } return numericMap; }, [firstLocalTable]);