Data grid

EuiDataGrid is for displaying large amounts of tabular data. It is a better choice over EUI tables when there are many columns, the data in those columns is fairly uniform, and when schemas and sorting are important for comparison. Although it is similar to traditional spreedsheet software, EuiDataGrid's current strengths are in rendering rather than creating content.

Core concepts

  • The grid allows you to optionally define an in memory level to have the grid automatically handle updating your columns. Depending upon the level choosen you may need to manage the content order separate from the grid.
  • Schemas allow you to tailor the render and sort methods for each column. The component ships with a few automatic schema detection and types, but you can also pass in custom ones.
  • Unlike tables, the data grid forces truncation. To display more content your can customize popovers to display more content and actions into popovers.
  • Grid styling can be controlled by the engineer, but augmented by user preference depending upon the features you enable.
name
email
location
account
date
amount
phone
version

Row: 1, Column: 1:

Boyer, Godfrey Sr.

Row: 1, Column: 2:

Row: 1, Column: 3:

Kreigerburgh, Montenegro

Row: 1, Column: 4:

51380179

Row: 1, Column: 5:

Sun Jan 06 2019 05:50:54 GMT+0000 (Greenwich Mean Time)

Row: 1, Column: 6:

$62.00

Row: 1, Column: 7:

604-345-3682 x2744

Row: 1, Column: 8:

9.6.9

Row: 2, Column: 1:

Johnston, Addie MD

Row: 2, Column: 2:

Row: 2, Column: 3:

Konopelskimouth, Brazil

Row: 2, Column: 4:

77980944

Row: 2, Column: 5:

Sun Jul 14 2019 12:35:31 GMT+0100 (British Summer Time)

Row: 2, Column: 6:

$473.00

Row: 2, Column: 7:

193.804.3849 x2690

Row: 2, Column: 8:

1.2.6

Row: 3, Column: 1:

Rempel, Gardner II

Row: 3, Column: 2:

Row: 3, Column: 3:

Jaredmouth, Tajikistan

Row: 3, Column: 4:

26822517

Row: 3, Column: 5:

Mon Jul 08 2019 05:17:42 GMT+0100 (British Summer Time)

Row: 3, Column: 6:

$829.00

Row: 3, Column: 7:

(723) 322-0380 x83783

Row: 3, Column: 8:

8.2.1

Row: 4, Column: 1:

Dickinson, Jesse Jr.

Row: 4, Column: 2:

Row: 4, Column: 3:

Pfefferstad, Jersey

Row: 4, Column: 4:

55770550

Row: 4, Column: 5:

Sat Sep 21 2019 19:03:45 GMT+0100 (British Summer Time)

Row: 4, Column: 6:

$534.00

Row: 4, Column: 7:

1-335-146-3794

Row: 4, Column: 8:

3.2.8

Row: 5, Column: 1:

Gutkowski, Arturo III

Row: 5, Column: 2:

Row: 5, Column: 3:

Evalynchester, Luxembourg

Row: 5, Column: 4:

20708011

Row: 5, Column: 5:

Sat Dec 22 2018 06:30:18 GMT+0000 (Greenwich Mean Time)

Row: 5, Column: 6:

$0.00

Row: 5, Column: 7:

182-469-7567

Row: 5, Column: 8:

9.2.7

Row: 6, Column: 1:

Mills, Clarabelle Sr.

Row: 6, Column: 2:

Row: 6, Column: 3:

Lamontshire, Belarus

Row: 6, Column: 4:

47839692

Row: 6, Column: 5:

Tue Nov 05 2019 23:32:15 GMT+0000 (Greenwich Mean Time)

Row: 6, Column: 6:

$885.00

Row: 6, Column: 7:

1-774-971-2327

Row: 6, Column: 8:

5.0.9

Row: 7, Column: 1:

Mitchell, Haley Sr.

Row: 7, Column: 2:

Row: 7, Column: 3:

East Selmer, Cayman Islands

Row: 7, Column: 4:

92944734

Row: 7, Column: 5:

Mon Jul 22 2019 06:37:41 GMT+0100 (British Summer Time)

Row: 7, Column: 6:

$300.00

Row: 7, Column: 7:

1-311-166-2628 x6812

Row: 7, Column: 8:

9.7.5

Row: 8, Column: 1:

Ankunding, Jordi IV

Row: 8, Column: 2:

Row: 8, Column: 3:

Lake Fae, Costa Rica

Row: 8, Column: 4:

40248610

Row: 8, Column: 5:

Wed Dec 12 2018 19:13:38 GMT+0000 (Greenwich Mean Time)

Row: 8, Column: 6:

$553.00

Row: 8, Column: 7:

369-211-7709

Row: 8, Column: 8:

3.2.3

Row: 9, Column: 1:

Wolf, Alphonso V

Row: 9, Column: 2:

Row: 9, Column: 3:

Row: 9, Column: 4:

93923378

Row: 9, Column: 5:

Fri Apr 05 2019 23:45:15 GMT+0100 (British Summer Time)

Row: 9, Column: 6:

$845.00

Row: 9, Column: 7:

047-934-0297

Row: 9, Column: 8:

3.6.9

Row: 10, Column: 1:

Hand, George II

Row: 10, Column: 2:

Row: 10, Column: 3:

Schinnerburgh, Equatorial Guinea

Row: 10, Column: 4:

20212205

Row: 10, Column: 5:

Thu Aug 15 2019 11:38:14 GMT+0100 (British Summer Time)

Row: 10, Column: 6:

$360.00

Row: 10, Column: 7:

(989) 340-1870

Row: 10, Column: 8:

8.3.1

Snippet with every feature in use

Here is a complicated data grid example meant to give you an idea of the data structure and callbacks you'll need to provide if you were utilizing all the features.


  <EuiDataGrid
    // Optional. Will try to autodectect schemas and do sorting and pagination in memory.
    inMemory={{ level: 'sorting' }}
    // Required. There are 200 total records.
    rowCount={200}
    // Required. Sets up three columns, the last of which has a custom schema we later define down below.
    // The second column B won't allow clicking in to see the content in a popup.
    columns={[{ id: 'A' }, { id: 'B', isExpandable: false }, {id: 'C', schema: 'franchise'}]}
    // Optional. This allows you to initially hide columns. Users can still turn them on.
    columnVisibility={{
      visibleColumns: ['A', 'C'],
      setVisibleColumns: () => {},
    }}
    // Optional. Customize the content inside the cell. The current example outputs the row and column position.
    // Often used in combination with useEffect() to dynamically change the render.
    renderCellValue={({ rowIndex, columnId }) =>
     `${rowIndex}, ${columnId}`
    }
    // Optional. Add pagination.
    pagination={{
      pageIndex: 1,
      pageSize: 100,
      pageSizeOptions: [50, 100, 200],
      onChangePage: () => {},
      onChangeItemsPerPage: () => {},
    }}
    // Optional, but required when inMemory is set. Provides the sort and gives a callback for when it changes in the grid.
    sorting={{
      columns: [{ id: 'C', direction: 'asc' }],
      onSort: () => {},
    }}
    // Optional. Allows you to configure what features the toolbar shows.
    // The prop also accepts a boolean if you want to toggle the entire toolbar on/off.
    toolbarVisibility={{
      showColumnSelector: false
      showStyleSelector: false
      showSortSelector: false
      showFullScreenSelector: false
    }}
    // Optional. Change the initial style of the grid.
    gridStyle={{
      border: 'all',
      fontSize: 'm',
      cellPadding: 'm',
      stripes: true,
      rowHover: 'highlight',
      header: 'shade',
    }}
    // Optional. Provide additional schemas to use in the grid.
    // This schema 'franchise' essentially acts like a boolean, looking for Star Wars or Star Trek in a column.
    schemaDetectors={[
      {
        type: 'franchise',
        // Try to detect if column data is this schema. A value of 1 is the highest possible. A (mean_average - standard_deviation) of .5 will be good enough for the autodetector to assign.
        detector(value) {
          return value.toLowerCase() === 'star wars' ||
            value.toLowerCase() === 'star trek'
            ? 1
            : 0;
        },
        // How we should sort data matching this schema. Again, a value of 1 is the highest value.
        comparator(a, b, direction) {
          const aValue = a.toLowerCase() === 'star wars';
          const bValue = b.toLowerCase() === 'star wars';
          if (aValue < bValue) return direction === 'asc' ? 1 : -1;
          if (aValue > bValue) return direction === 'asc' ? -1 : 1;
          return 0;
        },
        // Text for what the ASC sort does.
        sortTextAsc: 'Star Wars-Star Trek',
        // Text for what the DESC sort does.
        sortTextDesc: 'Star Trek-Star Wars',
        // EuiIcon to signify this schema.
        icon: 'star',
        // The color to use for the icon.
        color: '#000000',
      },
    ]}
    // Optional. Mapped against the schema, provide custom layout and/or content for the popover.
    popoverContents={{
      numeric: ({ children, cellContentsElement }) => {
        // `children` is the datagrid's `renderCellValue` as a ReactElement and should be used when you are only wrapping the contents
        // `cellContentsElement` is the cell's existing DOM element and can be used to extract the text value for processing, as below

        // want to process the already-rendered cell value
        const stringContents = cellContentsElement.textContent;

        // extract the groups-of-three digits that are right-aligned
        return stringContents.replace(/((\d{3})+)$/, match =>
          // then replace each group of xyz digits with ,xyz
          match.replace(/(\d{3})/g, ',$1')
        );
      },
    }}
  />

General props explanation

Please check the props tab in the example above for more explanation on the lower level object types. The majority of the types are defined in the /data_grid/data_grid_types.ts file.

columns
An array of EuiDataGridColumn objects. Lists the columns available and the schema and settings tied to it.
inMemory
A EuiDataGridInMemory object to define the level of high order schema-detection and sorting logic to use on your data. Try to set it when possible. If omitted, disables all enhancements and assumes content is flat strings.
columnVisibility
An array of EuiDataGridColumnVisibility objects. Defines which columns are visible in the grid and the order they are displayed.
schemaDetectors
An array of custom EuiDataGridSchemaDetector objects. You can inject custom schemas to the grid to define the classnames applied.
popoverContents
An object mapping EuiDataGridColumn schemas to a custom popover render. This dictates the content of the popovers when you click into each cell.
rowCount
The total number of rows in the dataset (used by e.g. pagination to know how many pages to list).
gridStyle
Defines the look of the grid. Accepts a partial EuiDataGridStyle object. Settings provided may be overwritten or merged with user defined preferences if toolbarVisibility.showStyleSelector is set to true (which is the default).
toolbarVisibility
Accepts either a boolean or EuiDataGridTooBarVisibilityOptions object. When used as a boolean, defines the visibility of entire toolbar. When passed an object allows you to turn off individual controls within the toolbar.
renderCellValue
A function called to render a cell's value. Behind the scenes it is treated as a React component allowing hooks, context, and other React concepts to be used. The function receives a EuiDataGridCellValueElement as its only argument.
pagination
A EuiDataGridPagination object. Omit to disable pagination completely.
sorting
A EuiDataGridSorting object that provides the sorted columns along with their direction. Omit to disable, but you'll likely want to also turn off the user sorting controls through the toolbarVisibility prop.