Table: Make the height of the table include header cells (#21824)

* Mak table panel with padding

* Make table have a correct height
pull/21834/head
Dominik Prokop 5 years ago committed by GitHub
parent 13948c0b76
commit 9882464505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      packages/grafana-ui/src/components/Table/Table.tsx
  2. 5
      public/app/plugins/panel/table2/module.tsx

@ -2,6 +2,7 @@ import React, { useMemo } from 'react';
import { DataFrame } from '@grafana/data';
import { useSortBy, useTable, useBlockLayout, Cell } from 'react-table';
import { FixedSizeList } from 'react-window';
import useMeasure from 'react-use/lib/useMeasure';
import { getColumns, getTableRows } from './utils';
import { useTheme } from '../../themes';
import { TableFilterActionCallback } from './types';
@ -17,6 +18,7 @@ export interface Props {
export const Table = ({ data, height, onCellClick, width }: Props) => {
const theme = useTheme();
const [ref, headerRowMeasurements] = useMeasure();
const tableStyles = getTableStyles(theme);
const { getTableProps, headerGroups, rows, prepareRow } = useTable(
@ -53,12 +55,17 @@ export const Table = ({ data, height, onCellClick, width }: Props) => {
<div {...getTableProps()} className={tableStyles.table}>
<div>
{headerGroups.map((headerGroup: any) => (
<div className={tableStyles.thead} {...headerGroup.getHeaderGroupProps()}>
<div className={tableStyles.thead} {...headerGroup.getHeaderGroupProps()} ref={ref}>
{headerGroup.headers.map((column: any) => renderHeaderCell(column, tableStyles.headerCell))}
</div>
))}
</div>
<FixedSizeList height={height} itemCount={rows.length} itemSize={tableStyles.rowHeight} width={width}>
<FixedSizeList
height={height - headerRowMeasurements.height}
itemCount={rows.length}
itemSize={tableStyles.rowHeight}
width={width}
>
{RenderRow}
</FixedSizeList>
</div>

@ -4,7 +4,4 @@ import { TablePanelEditor } from './TablePanelEditor';
import { TablePanel } from './TablePanel';
import { Options, defaults } from './types';
export const plugin = new PanelPlugin<Options>(TablePanel)
.setNoPadding()
.setDefaults(defaults)
.setEditor(TablePanelEditor);
export const plugin = new PanelPlugin<Options>(TablePanel).setDefaults(defaults).setEditor(TablePanelEditor);

Loading…
Cancel
Save