DataTableV2
The DataTableV2 is a component for building tables which organize information
into rows and columns.
Import
import { DataTableV2 } from '@dynatrace/strato-components-preview/tables';
Use cases
It is important that the data and columns prop passed to the DataTableV2
are memoized. Use the useMemo hook to make sure the props do not change on
each render cycle.
Please note that the DataTableV2, which relies on the CSS Grid for its layout,
is currently limited to a maximum of 10,000 columns, including built-in columns.
Exceeding this limit may cause rendering issues in some browsers. This
restriction is based on the limit enforced by Firefox, which applies the
recommendation of the
W3C CSS Grid Layout Module.
Accessors
Accessors specify how to retrieve column data from your data structure. Accessor strings that contain dots allow you to retrieve nested data. If the actual property key contains a dot, you can escape an accessor by enclosing the string in square brackets. It is also possible to specify an accessor function that returns the value you want to extract. See the code below for examples of each.
Text alignment
If no column type is set, text within the cell is left-aligned by default. To
explicitly change the default alignment, use the alignment property in the
column definition.
Define header groups
It is possible to define header groups by providing a nested array of columns
via the columns property in the column definition. Currently, a header group
can only contain columns and not another nested header group.
Define column types
You can assign a predefined type to every column. Values in those columns will
be rendered and sorted according to each type. Available types are text,
date, bit, number, long, currency, log-content, sparkline,
meterbar, markdown and gantt.
By default, columns of type text will automatically detect links and render
them as such. If you want to disable this feature, set the detectLinks prop in
the column config to false. In case you are using a custom cell renderer, a
detectLinks function is available for you to apply.
When setting the column type to log-content, only the first 1000 characters
will be highlighted in order to keep performance optimized for datasets of any
size. Further, log lines will be truncated after 1000 characters. This limit can
be changed via the truncationLimit property in the column config. Note that
any trailing whitespace is removed after truncation.
Customize markdown rendering
Use the customComponentMappings config to override the default markdown
rendering behavior.
import { Components } from '@dynatrace/strato-components-preview/core';
const customMappings: Components = {
  h2: ({ children }: PropsWithChildren) => (
    <i>
      <h2>{children}</h2>
    </i>
  ),
};
const columns = [
  // ...
  {
    header: 'Markdown',
    accessor: 'markdown',
    id: 'markdown',
    columnType: 'markdown',
    width: 220,
    config: { customComponentMappings: customMappings },
  },
];
Font style
The DataTableV2 allows for the customization of font styles across the entire
table or within individual columns. This can be achieved by configuring it in
the table variant options or the column definition.
Provide sub-rows
The DataTableV2 component offers the capability to include sub-rows.
- 
Enable sub-rows - To activate this functionality, the subRowsprop must be defined. This prop accepts either a boolean value, which activates the default sub-row view, or an object configuration.
- 
Provide sub-rows data - Simply define the respective sub-row data by adding the subRowsproperty to the parent row's data definition. The specified sub-rows must have the same data structure as the parent rows and can be nested over multiple levels.
Use the defaultOpenSubRows prop to specify sub-rows that are already open upon
initial rendering. The onOpenSubRowsChange handler allows you to react to
changes in the currently open sub-rows.
The defaultOpenSubrows/openSubRows expects the id of the row (unless
otherwise specified, this is the array index of the data) along with a boolean
whether or not it's opened. Nested sub-rows are separated with a dot by default,
so '0.0' would be the first row's first sub-row. For details on how to customize
row IDs, reference the control row IDs section.
Configure sub-rows
To further configure sub-rows, you can pass a configuration object to the
subRows prop, using the following options:
- 
accessor- Provide a customaccessorfor retrieving the corresponding sub-rows for each row from the data.
- 
subRowColumnId- Specify the id of the column that the sub-row indicator should be injected to. By default, this is the first visible column.
- 
disableSubRow- Accepts a function that will evalute whether or not a specific sub-rows trigger in a row should be disabled.
Control sub-rows
To control the state of the open sub-rows, provide the desired rows using the
openSubRows prop along with a handler for the onOpenSubRowsChange callback.
Use the Sparkline chart
It is possible to pass timeseries data to the DataTableV2 and visualize it
with a Sparkline chart. To achieve this, you need to set columnType to
sparkline in the column definition and use the column accessor to point to
the timeseries data that you want to process.
The Sparkline chart in the DataTableV2 can be further configured via the
column definition. You can set its color and variant by adding
config: {color: string, variant: 'line' | 'area' | 'bar'}. The default
configuration of sparkline is
config: {color: 'categorical', variant: 'line', showContextValues: false}.
Use the MeterBarChart
You can visualize numerical data within the DataTableV2 by using
MeterBarCharts. For more information about the MeterBarChart, refer to the
documentation. To render a
MeterBarChart in the table, follow these steps:
- Set columnTypetometerbarin the column definition
- Use the accessorproperty to specify which value data you want to process.
The MeterBarChart in the DataTableV2 column can be further customized through
the column definition. You can configure its appearance by using the config
prop, which includes the following options:
- color (string): Specifies the color of the MeterBarChart.
- min (number): Sets the minimum value for the MeterBarChart.
- max (number): Sets the maximum value for the MeterBarChart.
- showTooltip (boolean): Controls whether tooltips are displayed.
- thresholds (array of objects {name: string, value: number, color: string}): Defines threshold values and their associated colors.
MultiMeterBarChart in tables
To add a MultiMeterBarChart to the DataTableV2, follow the steps in
MeterBarChart in tables and then provide an array of value objects
(value: {name: string, value: number, color: string}) as data, this will
enable DataTableV2 to visualize a MultiMeterBarChart. For more information
about the MultiMeterBarChart, refer to the
documentation.
Again, similar to the MeterBarChart, you can fine-tune the
MultiMeterBarCharts appearance by setting the colorPalette property to
define a color pattern specifically tailored for the MultiMeterBarChart.
When data is provided as value array objects, color and thresholds props in
config are ingored.
Use the Gantt chart
To visualize column data with a Gantt chart, set the columnType to gantt. The
Gantt column definition also accepts a config prop in the format
DataTableV2GanttColumnConfig, which allows configuration of the following
options:
- min: Axis configuration for the minimum value (- MinScaleBoundary).
- max: Axis configuration for the maximum value (- MaxScaleBoundary).
- xAxisType: Whether the axis type is- numericalor- time.
- nameAccessor: String accessor for the segment's name, which is displayed in the tooltip.
- colorAccessor: String accessor for the segment's color.
- colorPalette: The palette that contains the segment color mapping.
- showBackground: Whether gaps between segments should receive a background.
- tooltipActions: Actions that should be displayed with the default tooltip. The function provides the- segment,- rowand- parentdata as parameters.
- tooltip: Custom tooltip implementation. The function provides the- segment,- rowand- parentdata as parameters.
- formatter: Formatter options from the- @dynatrace-sdk/unitspackage.
The data for the Gantt chart must contain the Gantt segment data in this format:
{ start: number; end?: number; }. Each row can display one or more Gantt
segments. If multiple segments should be displayed, you can pass an array of
segment data. The segment data can also contain further properties, e.g. for
configuring its color or name, if the corresponding accessor was specified in
the config.
Enable full width
By default, the DataTableV2 is set to automatically expand and occupy the full
width of its parent element. However, this behavior changes when the table is
placed within a flex container. In such cases, if you wish to ensure that the
table maintains full width, you can include the fullWidth prop when using the
DataTableV2 component.
When this value is not set, it will grow as needed based on the number of columns and their width.
Enable full height
By default, the DataTableV2 grows as needed based on the number of rows. When
placed inside a container, the table's height can be the same as its parent or
smaller depending on how many rows would be visible inside the parent container.
If you wish to ensure that the table always occupies the full height of its
parent element, you can include the fullHeight prop when using the
DataTableV2 component.
Keep in mind that the fullHeight prop should be applied carefully. Setting
fullHeight on the table that is placed inside a container that takes up the
height of the page can lead to serious performance issues. It is therefore
advisable to use the prop in combination with a well-defined container height.
Control column width behavior via column definitions
The DataTableV2 provides multiple ways of controlling the column width
behavior.
- 
Fixed width in pixels: You can set a fixed width for the column by specifying the exact number of pixels. For example, width: 100would set the column to be 100 pixels wide.
- 
Minimum and maximum width constraints: You can specify minWidthandmaxWidthin the exact number of pixels to set width boundaries for a column.maxWidthwill not work on fraction widths, to avoid circular width calculations.
- 
Flexible width in fractions: You can set a flexible width for the column using a fractional unit. This is done by specifying the width as a fraction, like width: '1fr'. This approach allows the column to take up a proportion of the available space, adjusting dynamically based on the total space available and the fractional values assigned to other columns. For instance, if you have two columns and set their widths towidth: '1fr'andwidth: '2fr', the second column will be twice as wide as the first one.
- 
Fit to content: To make a column's width automatically adjust to fit the content of its cells, set the column's widthproperty tocontent.
- 
Shared leftover space: If you want certain columns to share the leftover space among themselves set the option to a fraction value for those columns. See the example in allow certain columns to occupy the remaining space 
- 
autowill hand over control about the column size to the browsers grid layout and follows the layout engine and specification of the browser. Reference MDN grid documentation for details.
- 
You can also set a maximum width for the column when using either of the previous two options by configuring it like this: {type: 'auto' | 'content', maxWidth: 100}. Here,maxWidthspecifies the maximum width in pixels.
Allow certain columns to occupy the remaining space
You will certainly have some columns in you DataTableV2 that are more
important than others. Between these columns, you can spread the remaining space
within the table by providing a fraction width like 1fr for the columns. In
the example below the columns Memory Total and Timestamp occupy each one
fraction of the remaining space, and the Price column takes up two fractions.
Column sizing
To establish default column widths for the table, you can utilize the
defaultColumnSizing as a DataTableV2 prop. This property requires an object
that maps column IDs to their respective widths in pixels.
Control column sizing
To activate the column resizing feature in DataTableV2, you need to include
the resizable property within the table’s configuration. This property acts as
a flag that, allows the columns within the table to be adjusted in width
interactively by the user.
You can track the changes in column widths during resizing events by utilizing
the onColumnSizingChange and columnSizing properties. The callback triggered
upon resizing delivers data regarding the current widths of all columns. This
information can be leveraged to record and maintain the dimensions of resized
columns. For instance, as demonstrated here, whenever the email column is
resized, it will revert to a default width of 300px.
As soon as a resizing event starts, all columns that have a fraction width or no width defined will be locked to their current width.
Customize visual representation
The variant prop allows you to customize the appearance of the DataTableV2
by setting the configuration options available in DataTableV2Props['variant'].
Row density
The rowDensity option adds spacing around the content within a row. By
default, rowDensity is set to default, which represents a medium spacing. If
the option is set to condensed, the spacing becomes minimal while
comfortable represents the maximum spacing.
Row separation
The rowSeparation option determines how rows should be separated visually. By
default, rowSeparation is set to horizontalDividers which adds lines between
the rows. zebraStripes additionally provides alternate row coloring. By
setting rowSeparation to none, the rows are not separated visually.
Vertical dividers
The verticalDividers option determines whether columns should be separated
visually. By default, false is set which does not separate the columns within
a DataTableV2. If verticalDividers is set to true, lines are added between
the columns.
Contained
The contained option provides a border for the DataTableV2. By default,
contained is set to true to display the border. If false is set, no border
is added.
Hidden headers
You can customize the DataTableV2's appearance to hide the entire header, by
setting headers: 'hidden'.
If you choose to hide the header, please note that the ability to sort columns by header, as well as any actions that could be triggered with column headers, won't be available. Also, column pinning will be disabled.
Vertical alignment
Use the verticalAlignment option to configure the vertical alignment of the
cell content. The alignment options are top, center, and bottom. It is
also possible to configure the vertical alignment for header and body cells
separately. By default, all cell content is top-aligned.
Customize cell rendering
To customize the cell rendering, pass the corresponding function to the cell
prop in the column definition. If you want to maintain default cell styling, you
need to wrap each return statement with DataTableV2.DefaultCell element. Also,
DataTableV2.DefaultCell supports className and style props, allowing
further customization of the cell appearance.
Within the function passed to the cell property, you can access the cell's
value, rowIndex, rowData and rowId. Additionally, the isLineWrapped
prop provides the current line wrap state of the column in which the cell is
rendered.
Moreover, a format, a formatLogContent and a detectLinks function are
available:
- format- Allows you to apply the- formatteroptions that have been configured for that cell (either via the column definition or via the columnType).
- formatLogContent- Formats the given text as a log output.
- detectLinks- Automatically detects links in the given text and renders them as such using the- ExternalLinkcomponent.
Customize column header
To customize the column header, simply utilize the header property within the
column definition. Assign a function to this property that returns a customized
JSX element. Similar to cell, if you want to maintain default header styling,
you need to wrap each return statement with DataTableV2.DefaultCell element.
Also, DataTableV2.DefaultCell supports className and style props, allowing
further customization of the header appearance.
Caution: Avoid placing interactive elements within a custom-rendered header if column actions are already configured for the same column. Since a column header with column actions already includes a button element, adding additional interactive elements inside may result in unexpected behavior.
Enable line wrap
The DataTableV2 component offers flexible options for managing the line
wrapping of cell content within your table. Here’s how you can control it:
- 
Global line wrapping configuration - To activate line wrapping across all columns, set the defaultLineWraporlineWrapproperty to true.
- 
Column-Specific line wrapping - If you prefer to enable or disable line wrapping for certain columns, pass an object to the defaultLineWrapproperty. Use column IDs as keys and set their values to true (to enable) or false (to disable).
- 
User-Controlled Line Wrapping - Toggle via column actions: Incorporate TableActionsMenu.LineWrapinto your table to allow users to switch line wrapping on or off for specific columns through the column actions menu.
- 
User-Controlled Line Wrapping (entire table) - Toggle via a DataTableV2.Toolbaraction: IncorporateDataTableV2.LineWrapinto you tablesDataTableV2.Toolbarcomponent to allow users to switch line wrapping on or off for all columns.
Props for Line Wrapping Control
The DataTableV2 also provides properties to manage line wrapping state:
- defaultLineWrap- Defines the initial state of line wrapping when the table loads.
- lineWrap- Sets the line wrapping state.
- onLineWrapChange- A callback function that triggers when the line wrapping state changes.
The DataTableV2 uses column virtualization to optimize performance. With line
wrap enabled, row heights might change while scrolling horizontally as wrapped
content becomes visible.
Enable sorting
By using the sortable flag, you can enable sorting for the entire table.
Additionally, you have the option to disable sorting on a per-column basis by
configuring the disableSorting property in the column definition. For
meterbar columns, sorting is disabled by default and
can be enabled explicitly by setting disableSorting to false. Please note
that sorting is not supported for
MultiMeterBarCharts.
By default, the first sorting direction is ascending. If you want to change
that, you can configure the sortDescFirst flag for the individual column.
There is also a possibility to invert the sorting logic. Setting sortInverted
to true means the underlying sorting direction will be inverted, but the UI
will not change. This could be useful, for example, when a lower score is
better. Values like null and undefined will be sorted with lower priority
and will always appear at the end of the list.
Columns can be sorted by clicking directly on the header, even on header cells with column actions defined. Sorting indicators and column action indicators are shown on hover or on sorted columns, which allow for header cells to be less cluttered, allowing to focus on the header's content
Sorting programmatically
Control sorting programmatically by setting the sortBy prop, passing an array
with column IDs and sorting directions. Use the onSortByChange callback to
monitor and manipulate sorting changes within the DataTableV2. If you want to
sort your data before it is passed to the table, you need to disable built-in
sorting by setting sortable={{ manualSorting: true }}. This is particularly
useful for server-side sorting. To initially sort tables without controlling
their state, use defaultSortBy.
Define a sortAccessor
In case the value that should be used for sorting differs from the one returned
by the accessor, it is possible to define a custom sortAccessor in the column
definition. For example, if the accessor returns an object, the sortAccessor may
return a number or string field within the object.
Define a custom sortType
You can specify a sortType in the column definition to control sorting
behavior more precisely. The built-in options are
'text' | 'textCaseSensitive' | 'number' | 'datetime'. However, for more
advanced scenarios, you can pass a function as well. This is particularly useful
for compound data, where a column displays multiple or combined data entries.
When using a custom sortType function, you may also need to define a custom
sortAccessor in your column definition. For details, see:
Define a sortAccessor.
In the example below, a column displays both CPU usage (as a percentage) and memory usage (in GB). The custom sorting function prioritizes higher CPU usage and resolves ties by considering higher memory usage.
Enable pagination
To enable pagination add the DataTableV2.Pagination component to your table.
This component allows you to configure the default page size and the default
page index via the defaultPageSize and defaultPageIndex props.
Change page size options
The default page size options are 10, 20, 50, 100, 250, 500 and 1000. To
customize these options, use the pageSizeOptions prop, which allows you to
pass the desired page sizes as an array. Please ensure that the passed (default)
page size aligns with the defined options. The table will not sanitize page
sizes that do not exist in the options.