Use certara-table to easily build out static tables with support for search, sort, and pagination. This component is built off of Grid.js.
As a cautionary note, this component is best used for static table. If the data within the table changes frequently (by user action, or async request, etc.) this component may not be the most performant. This is due to the way Grid.js re-renders the table when the data changes. In order to change the data in a cell, the entire table needs to be re-rendered to calculate the height and width of the table and all of its cells. The best use case for this component is a drop in replacement for datatables.
When you use <CertaraTable> from @certara/certara-ui-react, you typically drive the grid with data and columns props instead of putting a static <table> like the above examples. To render React components inside cells, use a column formatter and wrap your JSX with the _() helper from gridjs-react.
Grid.js uses Preact to render the elements in the cells _ is the exposed Preact render function. This is what allows you to render custom JSX and react components within the grid.js formatters. Preact works almost identically to normal React. See the Grid.js docs for more information.
When applying custom jsx rendering in certara-table like the above example, there are two different “pieces” to consider: the presentation, and the searchable data.
What the user see’s is based on what the column’s formatter function returns, whether it is jsx, string, or anything else. This isn’t necissarily “the data inside of the cell” from a conceptual standpoint. That means, what is returned from the formatter function isn’t sortable, or searchable, it is purly presentation.
The data layer, or what is returned from the column’s data function, is what is used for sorting and searching. If you’d like your fancy react columns to have some specific, sortable and searchable data, you’ll need to return that from the column’s data function.
For an advanced usage example, see the TFL’s project
While data loads, show certara-skeleton-table in an absolutely positioned layer over the same area where the table will appear. Give the wrapper position-relative and a min-height so the skeleton has space before the real table mounts.
Automatically refresh the table when the data prop changes
bordered
Attribute
bordered
Type
boolean
Default
false
Required
false
Description
Puts borders between table data cells
columns
Attribute
undefined
Type
(string | TableColumn)[]
Default
undefined
Required
false
Description
Column names (strings) or column config objects. See https://gridjs.io/docs/config/columns. Set with JS when the component is used in an HTML context.
data
Attribute
undefined
Type
any[]
Default
undefined
Required
false
Description
Can be an array of arrays, or an array of objects. This needs to be set with JS when the component is in an HTML context
fixedHeader
Attribute
fixed-header
Type
boolean
Default
false
Required
false
Description
Fixed headers also require a set height
from
Attribute
undefined
Type
HTMLTableElement
Default
undefined
Required
false
Description
Reference to an existing HTML <table> element to use as the data source. GridJS will read the data from this table. Alternatively, place a <table> element as a child of <certara-table> and it will be auto-detected. See: https://gridjs.io/docs/examples/from
fullHeight
Attribute
full-height
Type
boolean
Default
true
Required
false
Description
The table container will stretch to the full height of the viewport
height
Attribute
height
Type
string
Default
undefined
Required
false
Description
Set height with CSS units (e.g. 400px)
offsetY
Attribute
offset-y
Type
string
Default
undefined
Required
false
Description
Offset to stretch table to fill available vertical space aside from reserved space for toolbars, etc. (e.g., 230px)
pagination
Attribute
pagination
Type
boolean | object
Default
undefined
Required
false
Description
Set to true to show pagination, configure extended options with the JS object (Docs)
resizable
Attribute
resizable
Type
boolean
Default
false
Required
false
Description
Allows columns to be resized
search
Attribute
search
Type
boolean
Default
false
Required
false
Description
Shows a built-in table filter search field
searchPlaceholder
Attribute
search-placeholder
Type
string
Default
'Search'
Required
false
Description
Placeholder text for built-in table search input
sort
Attribute
sort
Type
boolean
Default
false
Required
false
Description
Allows simple sorting on columns. More complex data needs to have custom rules in the columns.sort.compare object
tableClassName
Attribute
table-class-name
Type
string
Default
undefined
Required
false
Description
Adds a className specifically to the rendered <table> element vs. the component wrapper