Schema & columns
Schemas
Schemas are data types you pass to grid columns to affect how the columns and expansion popovers render. Schemas also allow you to define individual sorting comparators so that sorts can do more than just A-Z comparisons. By default, EuiDataGrid ships with a few built-in schemas for
numeric, currency, datetime, boolean and json
data. When the inMemory
prop is in use it will automatically try to figure out the best schema based on the inMemory:{{ level: value }}
you set, but this will come with the caveat that you will need to provide and manage sorting outside the component. In general we recommend passing schema information to your columns instead of using auto-detection when you have that knowledge of your data available during ingestion.Defining custom schemas
Custom schemas are passed as an array to schemaDetectors
and are constructed against the EuiDataGridSchemaDetector interface. You can see an example of a simple custom schema used on the last column below. In addition to schemas being useful to map against for cell and expansion rendering, any schema will also add a className="euiDataGridRowCell--schemaName"
to each matching cell.
Columns
Column widths
By default, visible columns are given equal widths to fill up available space in the grid and can be resized by the user to any desired width. There are two parameters on EuiDataGridColumn to change this default behavior. initialWidth
is a numeric value providing the starting width of a column, in pixels. Second, the isResizable
value can be set to false
to remove the user's ability to resize column.
Below, the first column is given an initial width and is not resizable. The second column is also given an initial width but its width can still be changed.
Column actions
By default, columns provide actions for sorting, moving and hiding. These can be extended with custom actions. You can customize the actions by setting the actions
value of EuiDataGridColumn. Setting it to false
removes the action menu displayed. You can configure it by passing an object of type EuiDataGridColumnAction. This allows you a hide, configure the existing actions and add new ones.
Below, the first column provides no action, the second doesn't provide the ability to hide the columns, the 3rd provides an additional action, the 4th overwrites the hide action with a custom label and icon.
Draggable columns
To reorder columns directly instead of via the actions menu popover, you can enable draggable EuiDataGrid header columns via the columnVisibility.canDragAndDropColumns
prop. This will allow you to reorder the column by dragging them.
Control columns
Control columns can be used to include ancillary cells not based on the dataset, such as row selection checkboxes or action buttons. These columns can be placed at either side of the data grid, and users are unable to resize, sort, or rearrange them.
These custom columns are defined by passing an array of EuiDataGridControlColumn objects (see Props tab below) to leadingControlColumns
and/or trailingControlColumns
.
As with the data grid's renderCellValue
, the control columns' headerCellRender
and rowCellRender
props are treated as React components.
Footer row
A footer row can be used to include value aggregations to the grid. Values could be based on the dataset, such as sum/average/min/max of numeric values in a column, or any other necessary data.
The footer row is defined by passing renderFooterCellValue
function prop into EuiDataGrid. This function acts like a React component, receiving EuiDataGridCellValueElementProps
and returning a React node.
When rendering footer cell values, we encourage turning off cell expansion on cells without content with setCellProps({ isExpandable: false })
.
Control columns will render empty footer cells by default, unless a custom footerCellRender
function is passed.
Props
EuiDataGridColumn
Prop | Description and type | Default value |
---|---|---|
Prop id# | Description and type The unique identifier for this column string | Default value Required |
Prop display# | Description and type A ReactNode | Default value |
Prop displayAsText# | Description and type Display name as text for the column. string | Default value |
Prop displayHeaderCellProps# | Description and type Optional props to pass to the column header cell HTMLAttributes<HTMLDivElement> | Default value |
Prop initialWidth# | Description and type Initial width (in pixels) of the column number | Default value |
Prop isExpandable# | Description and type Defaults to true, always true if cellActions are defined. Defines whether or not the column's cells can be expanded with a popup onClick / keydown. boolean | Default value |
Prop isResizable# | Description and type Whether this column's width can be changed by the user, defaults to true boolean | Default value |
Prop isSortable# | Description and type Whether this column is sortable boolean | Default value |
Prop defaultSortDirection# | Description and type Default sort direction of the column "asc" | "desc" | Default value |
Prop schema# | Description and type A Schema to use for the column. string | Default value |
Prop actions# | Description and type Configuration of column actions. Set to false to disable or use #EuiDataGridColumnActions to configure the actions displayed in the header cell of the column. false | EuiDataGridColumnActions | Default value |
Prop cellActions# | Description and type Additional actions displayed as icon on hover / focus, and in the expanded view of the cell containing the value EuiDataGridColumnCellAction[] | Default value |
Prop visibleCellActions# | Description and type Configures the amount of cell action buttons immediately visible on a cell. number | Default value |
EuiDataGridColumnActions
Prop | Description and type | Default value |
---|---|---|
Prop showHide# | Description and type Show/hide/configure the action to hide a column, provided EuiListGroupItemProps are merged boolean | EuiListGroupItemProps | Default value |
Prop showMoveLeft# | Description and type Show/hide/configure the action that switches the actual column with the column to the left side, provided EuiListGroupItemProps are merged boolean | EuiListGroupItemProps | Default value |
Prop showMoveRight# | Description and type Show/hide/configure the action that switches the actual column with the column to the right side, provided EuiListGroupItemProps are merged boolean | EuiListGroupItemProps | Default value |
Prop showSortAsc# | Description and type Show/hide/configure the action to sort ascending by the actual column, provided EuiListGroupItemProps are merged boolean | EuiListGroupItemProps | Default value |
Prop showSortDesc# | Description and type Show/hide/configure the action to sort descending by the actual column, provided EuiListGroupItemProps are merged boolean | EuiListGroupItemProps | Default value |
Prop additional# | Description and type Append additional actions EuiListGroupItemProps[] | Default value |
EuiDataGridColumnCellActionProps
Prop | Description and type | Default value |
---|---|---|
Prop rowIndex# | Description and type The index of the row that contains cell's data number | Default value Required |
Prop colIndex# | Description and type The index of the column that contains cell's data number | Default value Required |
Prop columnId# | Description and type The id of the column that contains the cell's data string | Default value Required |
Prop Component# | Description and type React component representing the action displayed in the cell. On cell hover/focus, an EuiButtonIcon will be displayed that cannot On cell expand, an EuiButtonEmpty will be displayed in the cell popover FunctionComponent<(DisambiguateSet<EuiButtonEmptyPropsForAnchor, EuiButtonEmptyPropsForButton> & CommonEuiButtonEmptyProps & { ...; } & ButtonHTMLAttributes<...>) | (DisambiguateSet<...> & ... 2 more ... & AnchorHTMLAttributes<...>)> | FunctionComponent<...> | Default value Required |
Prop isExpanded# | Description and type Determines whether the cell's action is displayed expanded (in the Popover) boolean | Default value Required |
EuiDataGridColumnVisibility
Prop | Description and type | Default value |
---|---|---|
Prop visibleColumns# | Description and type An array of #EuiDataGridColumn string[] | Default value Required |
Prop setVisibleColumns# | Description and type A callback for when a column's visibility or order is modified by the user. (visibleColumns: string[]) => void | Default value Required |
Prop canDragAndDropColumns# | Description and type Enables reordering grid columns on drag and drop via the headers cells boolean | Default value |
EuiDataGridControlColumn
Prop | Description and type | Default value |
---|---|---|
Prop id# | Description and type Used as the React string | Default value Required |
Prop width# | Description and type Width of the column, users are unable to change this number | Default value Required |
Prop headerCellRender# | Description and type Component to render in the column header ComponentType | Default value Required |
Prop rowCellRender# | Description and type Component to render for each row in the column RenderCellValue | Default value Required |
Prop headerCellProps# | Description and type Optional props to pass to the column header cell HTMLAttributes<HTMLDivElement> | Default value |
Prop footerCellRender# | Description and type Component to render in the optional column footer RenderCellValue | Default value |
Prop footerCellProps# | Description and type Optional props to pass to the column footer cell HTMLAttributes<HTMLDivElement> | Default value |
EuiDataGridSchemaDetector
Prop | Description and type | Default value |
---|---|---|
Prop type# | Description and type The name of this data type, matches #EuiDataGridColumn / string | Default value Required |
Prop detector# | Description and type The function given the text value of a cell and returns a score of [0...1] of how well the value matches this data type (value: string) => number | Default value Required |
Prop icon# | Description and type The icon used to visually represent this data type. Accepts any IconType | Default value Required |
Prop sortTextAsc# | Description and type Text for how to represent an ascending sort of this data type, e.g. 'A -> Z' ReactNode | Default value Required |
Prop sortTextDesc# | Description and type Text for how to represent a descending sort of this data type, e.g. 'Z -> A' ReactNode | Default value Required |
Prop comparator# | Description and type A custom comparator function when performing in-memory sorting on this data type, takes (a: string, b: string, direction: "asc" | "desc", indexes: { aIndex: number; bIndex: number; }) => 0 | 1 | -1 | Default value |
Prop color# | Description and type The color associated with this data type; it's used to color the icon token string | Default value |
Prop isSortable# | Description and type Whether columns with this schema are sortable (defaults to true). Can be overridden at the individual #EuiDataGridColumn level boolean | Default value |
Prop textTransform# | Description and type This property controls the capitalization of text "capitalize" | "lowercase" | "uppercase" | Default value |
Prop defaultSortDirection# | Description and type Default sort direction of columns with this schema. Can be overridden at the individual #EuiDataGridColumn level "asc" | "desc" | Default value |