Data table
Data table
Component demo
Interactive example
<ic-data-tablecaption="Basic Table"></ic-data-table>
Data table details
Props
All components also accept native properties supported by the DOM, such asclassName
and
style
.
|
|
|
---|---|---|
|
The title for the table only visible to screen readers. |
|
|
The column headers for the table. |
|
|
Determines whether the column header should be truncated and display a tooltip. Default is |
|
|
The row content for the table. |
|
|
Set the density of the table including font and padding. |
|
|
If |
|
|
Applies a border to the table container. |
|
|
Sets the row height on all rows in the table that aren't set using the |
|
|
Sets the table height. Can be set to |
|
|
If |
|
|
When set to |
|
|
Sets the props for the circular loading indicator used in the loading state. |
|
|
Sets the maximum width of the data table. Can be set in |
|
|
Sets the minimum width of the data table. Can be set in |
|
|
The minimum amount of time the |
|
|
Sets the props for the built-in pagination bar. If the |
|
|
If |
|
|
If |
|
|
Sets the order columns will be sorted in and allows for 'default' sorts to be added. |
|
|
If |
|
|
If |
|
|
If |
|
|
Sets the layout of the table |
|
|
Sets the theme color to the dark or light theme color. "inherit" will set the color based on the system settings or ic-theme component. |
|
|
Sets the method used to truncate long text in cells where textWrap is |
|
|
If |
|
|
Sets the props for the linear loading indicator used in the updating state. |
|
|
Allows for custom setting of row heights on individual rows based on an individual value from the |
|
|
Sets the table width. Can be set to |
|
The title for the table only visible to screen readers. |
The column headers for the table. |
Determines whether the column header should be truncated and display a tooltip. Default is |
The row content for the table. |
Set the density of the table including font and padding. |
If |
Applies a border to the table container. |
Sets the row height on all rows in the table that aren't set using the |
Sets the table height. Can be set to |
If |
When set to |
Sets the props for the circular loading indicator used in the loading state. |
Sets the maximum width of the data table. Can be set in |
Sets the minimum width of the data table. Can be set in |
The minimum amount of time the |
Sets the props for the built-in pagination bar. If the |
If |
If |
Sets the order columns will be sorted in and allows for 'default' sorts to be added. |
If |
If |
If |
Sets the layout of the table |
Sets the theme color to the dark or light theme color. "inherit" will set the color based on the system settings or ic-theme component. |
Sets the method used to truncate long text in cells where textWrap is |
If |
Sets the props for the linear loading indicator used in the updating state. |
Allows for custom setting of row heights on individual rows based on an individual value from the |
Sets the table width. Can be set to |
Slots
A slot allows for any type of element or markup to be passed into and rendered within a web component. This creates more flexibility than using a prop which must take a specific type of data.
Content can be slotted into a component by adding it as a top-level child of the component.
Slots can have a name to identify them. These specify which slot the content will be inserted into, and therefore where it will be rendered and how it will be used within the component. The name of the slot to be used can be specified by passing it via a
slot
attribute on the slotted content.
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Events
All components also accept native events supported by the DOM, such as
onClick
and
onKeyDown
.
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Methods
|
|
|
---|---|---|
|
|
|
|
Variants
Embedded
Theembedded
prop adds a border around the table so it can be added as a standalone table and is not required to stretch the full width of its parent container.
Interactive example
<ic-data-tablecaption="Embedded Table"embedded="true"></ic-data-table>
Dense
Thedensity
variant provides three different styles for the data table:
-
dense
reduces the padding and font size of the table cells to give the data a more dense style. -
default
provides a padding of8px
which is the default spacing. This variant is seen in thecomponent demo -
spacious
gives the data table a more spacious look and feel by increasing the vertical padding as well as the font size.
Interactive example
<ic-data-tablecaption="Dense Table"density="dense"></ic-data-table>
Spacious
Interactive example
<ic-data-tablecaption="Spacious Table"density="spacious"></ic-data-table>
Sticky column headers
When a height for the data table is set, the scroll bar will appear to the right. However, by default, the column headers will move up and out of view making it difficult to understand what the data means.
This can be mitigated by using thestickyColumnHeaders
prop which takes a boolean. This can be toggled within the example below.
Interactive example
<ic-data-tablecaption="Sticky header Table"sticky-column-headers="true"></ic-data-table>
Row headers
Row headers allow headings to be added to individual rows and styles them as column headings. The column collection includes an additionalheader
key which aligns with the row headers. The structure of theheader
column is the same as the columns (i.e.key
,title
,dataType
).
The data array includes an additionalheader
key within therowOptions
which takes a string intended to be the title of the row header.
Interactive example
<ic-data-tablecaption="Row headers"></ic-data-table>
Sortable
Setsortable
totrue
to set the sort functionality on all columns. Sorting can be set tounsorted
,ascending
anddescending
by pressing the sort buttons next to the column heading.
SetdisableAutoSort
to enable external sorting functionality. Alternatively, setdisableAutoSort
within the column object to have it apply only to certain columns that may require special custom sorting.
Interactive example
<ic-data-tablecaption="Sort"sortable="true"></ic-data-table>
Sort options
It is possible to change the sort options for the sort buttons. ThesortOptions
prop takes an object withsortOrders
anddefaultColumn
.sortOrders
allows the sort order to be amended as well as allowing sort types to be removed - such as changing the order todescending
andunsorted
, and removingascending
.defaultColumn
sets which column is ordered by default. This is set by putting the column key as thedefaultColumn
value.
Interactive example
<ic-data-tablecaption="Sort Options"sortable="true"></ic-data-table>
Exclude columns from sort
AddingexcludeColumnFromSort: true
to the column object excludes that column from displaying the sort button.
Interactive example
<ic-data-tablecaption="Exclude columns from sort"sortable="true"></ic-data-table>
Pagination
Pagination allows large data sets to be split into pages in order to make the data easier to digest. SettingshowPagination
totrue
will add the
paginationBarOptions
prop:
-
itemsPerPage
allows customisation of the number of items on each page. This requires a collection withlabel
andvalue
key pairs. -
showItemsPerPageControl
shows or hides theitemsPerPage
component usingtrue
orfalse
. -
showGoToPageControl
displays controls which allows jumping between pages in a non-linear approach.
Interactive example
<ic-data-tablecaption="Pagination"show-pagination="true"></ic-data-table>
Slotted pagination
There may be scenarios when pagination and data fetching is done using a backend API.
To enable this behaviour, thepagination-bar
slot can be utilised to provide a customic-pagination-bar
component, allowing the user to have more control over how their data is displayed and interacted with.
Interactive example
<ic-data-tablecaption="Slotted pagination bar"><ic-pagination-barslot="pagination-bar"show-items-per-page-control="true"></ic-pagination-bar></ic-data-table>
Pagination – with setToFirstPageOnPaginationChange
Interactive example
<ic-data-tablecaption="Pagination with page reset on items per page change"show-pagination="true"></ic-data-table>
Column overrides
There may be a requirement to style a column differently to the rest of the data to add emphasis. To do this, addcolumnAlignment
to the column, as demonstrated with the 'First name' column below.columnAlignment
takes an object which sets thehorizontal
andvertical
property:
-
horizontal
acceptsleft
,right
orcenter
. -
vertical
acceptstop
,middle
,bottom
.
emphasis
can be added to the column by settinghigh
orlow
.
Interactive example
<ic-data-tablecaption="Column Overrides"></ic-data-table>
Row overrides
Row overrides allow styling to be applied at a row level and is set within therowOptions
object. The following row overrides options apply:
-
rowAlignment
acceptsleft
,right
andcenter
. -
emphasis
acceptshigh
orlow
. -
textWrap
acceptstrue
orfalse
.
Interactive example
<ic-data-tablecaption="Row Overrides"></ic-data-table>
Cell overrides
Cell overrides allow styling to be applied at a cell level. The cell which requires an override accepts an object which requiresdata
and can containcellAlignment
and/oremphasis
:
-
data
is the cell value. -
emphasis
acceptshigh
orlow
. -
cellAlignment
accepts an object with the following key pairs:-
horizontal
acceptsleft
,right
orcenter
. -
vertical
acceptstop
,middle
,bottom
.
-
Interactive example
<ic-data-tablecaption="Cell Overrides"></ic-data-table>
Default Empty State
When the table receives no data (eithernull
or an empty array), it will automatically show anic-empty-state
below the headers.
Interactive example
<ic-data-tablecaption="Default Empty State"></ic-data-table>
Slotted Empty State
You can customise your own
empty-state
slot, to reflect different scenarios.
Interactive example
<ic-data-tableid="data-table"caption="Slotted Empty State"><ic-empty-statealigned="left"heading="Data source error"body="Error loading new data"><ic-buttonslot="actions">Retry</ic-button></ic-empty-state></ic-data-table>
Loading state
When a user wants to fetch their data asynchronously, aloading
prop can be set totrue
, which then renders a circular variant of the
The loading indicator can be customised using theloadingOptions
prop:
-
description
sets the aria-label of the component. -
label
sets the visual message. -
labelDuration
is the number of milliseconds before the label changes. -
overlay
renders a dark overlay over the previous data set while new data is loaded.
If it needs to be determinate, usemax
,min
andprogress
.
Interactive example
<ic-data-tableid="data-table"caption="Loading State"></ic-data-table>
Updating state
If data in the table has changed, anupdating
prop has been supplied to show a linearic-loading-indicator
just above the data rows.
This prop is also accompanied by anupdatingOptions
prop, which contains similar options toloadingOptions
, minuslabel
andlabelDuration
.
Interactive example
<ic-data-tableid="data-table"caption="Updating State"></ic-data-table>
Links and Elements in data
Custom HTML elements can be slotted or passed via thedata
prop to display in certain cells. When using the slotted method, the slot name follows the format of{COLUMN_TAG}-{ROW_INDEX}
.
Interactive example
<ic-data-tablecaption="Links and Elements in data"></ic-data-table>
Custom icons
Custom icons can be added to cells, columns and headers in the data table. To add it to headers, set the icon via thecolumns
prop:
icon: {
icon: //ICON_STRING_GOES_HERE,
onAllCells: //Boolean to determine whether column header icon should be replicated on all cells in the column,
hideOnHeader: //Boolean for whether this icon should only be shown on cells and not on the header,
}
To add icons to individual cells, they can be added through thedata
prop, in a similar method to overriding the cell. Cell icons take priority over theonAllCells
prop, meaning specific cells can be made to stand out.
Both cells and headers can also have icons slotted in. Cells use the slot format:{COLUMN_KEY}-{ROW_INDEX}-icon
, and headers use the format:{COLUMN_KEY}-column-icon
. Slotted icons take priority over icons inserted via thecolumns
anddata
props.
Interactive example
<ic-data-tableid="data-table"caption="Custom Icons"><svgslot="age-column-icon"xmlns="http://www.w3.org/2000/svg"viewBox="0 0 24 24"><pathd="M12 6C13.11 6 14 5.1 14 4C14 3.62 13.9 3.27 13.71 2.97L12 0L10.29 2.97C10.1 3.27 10 3.62 10 4C10 5.1 10.9 6 12 6M18 9H13V7H11V9H6C4.34 9 3 10.34 3 12V21C3 21.55 3.45 22 4 22H20C20.55 22 21 21.55 21 21V12C21 10.34 19.66 9 18 9M19 20H5V17C5.9 17 6.76 16.63 7.4 16L8.5 14.92L9.56 16C10.87 17.3 13.15 17.29 14.45 16L15.53 14.92L16.6 16C17.24 16.63 18.1 17 19 17V20M19 15.5C18.5 15.5 18 15.3 17.65 14.93L15.5 12.8L13.38 14.93C12.64 15.67 11.35 15.67 10.61 14.93L8.5 12.8L6.34 14.93C6 15.29 5.5 15.5 5 15.5V12C5 11.45 5.45 11 6 11H18C18.55 11 19 11.45 19 12V15.5Z"/></svg></ic-data-table>
Custom row heights
A data table can have its rows use custom heights, to help display more data per row. This involves using theglobalRowHeight
prop, which applies this custom height to all rows.
For a more granular approach,variableRowHeight
exists. This is passed through the data object for each row of data, as well as that row'sindex
. Using these properties, you can write a custom function that will return a number for that row's height based on your criteria.
Returningnull
from this function means that the row will use theglobalRowHeight
property value.
NOTE:
If the data table uses thedensity
prop, then your custom value will be scaled depending on the density, in order to keep content readable as the text size changes:
-
Dense
= 80% ofglobalRowHeight
orvariableRowHeight
. -
Spacious
= 120% ofglobalRowHeight
orvariableRowHeight
.
For example, ifglobalRowHeight
= 100, a dense table will set the height to be
80
.
NOTE:
If a cell has a description (see
For example, ifglobalRowHeight
= 100 and a cell has a description with a height of 20, then the row height for that cell's row will be set to
120
.
To quickly reset all row heights to the default, you can run theresetRowHeights
method.
If you would rather let the row calculate its own height based on its content, either setglobalRowHeight
toauto
, or returnauto
fromvariableRowHeight
.
Interactive example
<ic-data-tableid="data-table"caption="Custom Row Heights"></ic-data-table>
Custom title bar
To add additional information about the data held in your data table, you can use thetitle-bar
slot to add anic-data-table-title-bar
, which will appear above the column headers.
The title bar can have a description and metadata added, to provide supporting information to display some context about the data to the user. Primary and custom action slots also exist to allow for actions to be performed that are related to the data, which can be prominently displayed.
Theic-data-table-title-bar
has a built-in density selector, which allows a user to quickly change the size and padding of cells to make it more readable. This can also be hidden if preferred.
Interactive example
<ic-data-tableid="data-table"caption="Coffee Orders"><ic-data-table-title-barslot="title-bar"description="A list of all coffee orders in the last year."metadata="3 items | Updated: 20/03/25"><ic-buttonslot="primary-action">Add new order</ic-button><ic-buttonslot="custom-actions"variant="icon"aria-label="Coffee 1"><svgxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 -960 960 960"width="24"><pathd="M180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h600q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm0-60h600v-600H180v600Zm56-97h489L578-473 446-302l-93-127-117 152Zm-56 97v-600 600Z"/></svg></ic-button><ic-buttonslot="custom-actions"variant="icon"aria-label="Coffee 2"><svgxmlns="http://www.w3.org/2000/svg"height="24"viewBox="0 -960 960 960"width="24"><pathd="M180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h600q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm0-60h600v-600H180v600Zm56-97h489L578-473 446-302l-93-127-117 152Zm-56 97v-600 600Z"/></svg></ic-button><ic-typographyslot="description"variant="body"><p> A log kept of all{' '}<ic-linkhref="#">coffee orders</ic-link> to refer back to.</p></ic-typography></ic-data-table-title-bar></ic-data-table>
Truncation - tooltip
When a row is given a set height, and has content that no longer fits into the cell area, the content becomes truncated. There are two types of truncation:
-
tooltip
: Adds a line-clamp to the cell and displays the message in a tooltip. -
show-hide
: Adds aSee more/See less
button underneath the cell text, allowing the user to display the full content should they wish.
These values are set using thetruncationPattern
prop.
By default,globalRowHeight
is set toauto
. If thetruncationPattern
prop is set totooltip
orshow-hide
whileglobalRowHeight
isauto
, the data will not appear truncated due to the row height being set to the height of the tallest data row.
To see the data truncated, theglobalRowHeight
orvariableRowHeight
needs to be explicitly set to a height which is shorter than data which has the most lines.
NOTE:
truncationPattern
only applies to a cell's main data value. If a cell has a description (see
Interactive example
<ic-data-tablecaption="Data table truncation - tooltip"truncation-pattern="tooltip"></ic-data-table>
Truncation - show/hide
Interactive example
<ic-data-tablecaption="Data table truncation - show/hide"truncation-pattern="show-hide"></ic-data-table>
Text wrap
Text can be set to wrap in a particular column, row or cell. Any column, row or cell that text wrap is applied to will ignore the custom height if the custom height is too small and the full content will be shown.
To set text to wrap in a column, addtextWrap: true
as a key value:
const column = [
{ key: "name", title: "Name", dataType: "string", textWrap: true },
...
]
To set text to wrap in a row, addrowOptions: { textWrap: true }
to an object within the data array:
const data = [
{
name: "Tim Rayes",
age: 41,
department: "Sales and Marketing",
employeeNumber: 3,
jobTitle:
"Regional Sales and Marketing Strategy Director (Europe, the Middle East, and Africa)",
rowOptions: {
textWrap: true
}
},
...
]
To set text wrap in a cell, addtextWrap
to a data key within an object:
const data = [
{
name: {
data: "Tim Rayes",
textWrap: true
},
age: 41,
department: "Sales and Marketing",
employeeNumber: 3,
jobTitle:
"Regional Sales and Marketing Strategy Director (Europe, the Middle East, and Africa)",
},
...
]
Interactive example
<ic-data-tablecaption="Data table text wrap"></ic-data-table>
Columns widths and table sizing
The dimensions of the data table can be set using thewidth
andheight
attributes. The attribute accepts dimensions inpx
,%
,rem
andauto
.
By default, the width is set to100%
so the table spans across the viewport or parent container.
To set the column widths, thecolumnWidth
property should be added to the relevant column within the column array.
The
By default, the table layout is set tofixed
. If no column width is set, the columns widths will be equally set within the viewport or parent container.
A table with afixed
layout will force the table column widths to take precedence over the data with the table cells.
For the column widths to be dictated by the content inside, set thetableLayout
prop toauto
and set the tablewidth
toauto
.
To set the min and max width of a table cell, set thetableLayout
prop toauto
and set aminWidth
ormaxWidth
value incolumnWidth
.minWidth
andmaxWidth
accept dimensions inpx
,%
,rem
.
Interactive example
<ic-data-tablecaption="Columns widths and table sizing"table-layout="auto"width="800px"></ic-data-table>
Description and icons within cells
Descriptions and icons can be included in the cells by proving adescription
field in the data. This will populate the cell with an icon (if provided) and a text string underneath the cell data. This can be applied to any cell.
You can provide adescription
object with or without an icon:
// With an icon
firstName: {
data: "Joe",
description: {
data: "The name of Joe",
icon: '<svg xmlns="http://www.w3.org/2000/svg" height="20" viewBox="0 -960 960 960" width="20"><path d="M180-120q-24 0-42-18t-18-42v-600q0-24 18-42t42-18h600q24 0 42 18t18 42v600q0 24-18 42t-42 18H180Zm0-60h600v-600H180v600Zm56-97h489L578-473 446-302l-93-127-117 152Zm-56 97v-600 600Z"/></svg>',
},
}
// Without an icon
firstName: {
data: "Joe",
description: "The name of Joe"
}
Interactive example
<ic-data-tablecaption="Description and icons within cells"table-layout="auto"></ic-data-table>
Missing cell data
If cell data is missing (represented as eithernull
,undefined
or""
) then the data table will still render an empty placeholder cell.
Interactive example
<ic-data-tablecaption="Missing cell data"></ic-data-table>
Select rows
By settingrowSelection
totrue
,
icSelectedRowChange
containing the selected row and an array of all the currently selected rows.
When checking the header checkbox, all rows will be selected, with theicSelectAllRows
event being emitted with an array of all the rows. When using pagination, only the rows on the current page will be selected.
Interactive example
<ic-data-tablecaption="Select rows with checkbox"row-selection="true"></ic-data-table>
Hidden columns
Addinghidden: true
to the column object hides that column. In this example, the Quantity column is hidden.
Interactive example
<ic-data-tablecaption="Hidden columns"></ic-data-table>