Examples › Column properties and styling
The accessor
The only property you have to specify for a column is its accessor
(the name of the record property you want to display in each column cell).
The accessor
supports dot-notation for nested objects property drilling (i.e. 'department.company.name'
).
The component will try to derive a column header title by “humanizing” the provided accessor (i.e. 'firstName'
→ 'First name'
or 'department.company.name'
→ 'Department company name'
).
If you’re not happy with the automatically derived title, you can override it by setting your own column title
.
Basic column properties
In addition, each column can be customized by specifying the following properties:
width: number | string
Desired column width.ellipsis: boolean
If true, cell content in this column will not wrap to multiple lines and will be truncated with ellipsis if/as needed.
You can either set this property totrue
or setnoWrap
totrue
, but not both.noWrap: boolean
If true, cell content in this column will not wrap on multiple lines (i.e.white-space: nowrap
).
You can either set this property totrue
or setellipsis
totrue
, but not both.textAlign: 'left' | 'center' | 'right'
Defaults to'left'
if not specified.hidden: boolean
If true, the column will not be visible.visibleMediaQuery
A media querystring
or a function accepting the currentMantineTheme
as its argument and returning a media-query string.
If set, the column will only be visible according to the specified media query.render
A method that accepts the current record as its argument and returns aReactNode
(keep in mind that strings and numbers are valid react nodes).filter
An optional property which provides the user with filtering options. It can be either aReactNode
or a function returning aReactNode
.
If aReactNode
is provided, a filter button will be added to the column header. Upon clicking the button, a popover showing the provided node will be opened.
Alternatively, you can provide a function returning aReactNode
. The function will be called with an object containing aclose()
method, which you can call to close the popover.filtering: boolean
If true, the column will be styled as an active filtering column. Defaults tofalse
if not specified.
You can create a “virtual column” by providing an accessor that doesn’t to refer an existing property (or nested property) name. In this case, you must provide a custom render
method. Also, keep in mind that each accessor name must be unique amongst the collection of columns.
Consider this example:
Here’s the code for the example above:
Column footers
The DataTable component will display a footer row at the bottom of the table if you specify a footer
property for at least one column:
Here’s the code for the example above:
Styling column titles, cells and footers
In addition, each column can be further customized by specifying the following styling properties:
titleClassName: string
A custom class name for the column title.titleStyle
A custom style object for the column title, or a function accepting the current theme and returning a style object.cellsClassName: string
A function that accepts the current record as its argument and returns astring
representing a custom class name for the column cells.cellsStyle
A function that accepts the current record as its argument and returns either a style object for the column cells, or a function accepting the current theme and returning a style object.footerClassName: string
A custom class name for the column footer.footerStyle
A custom style object for the column footer, or a function accepting the current theme and returning a style object.
Consider this example:
Here’s the code for the example above:
Head over to the next example to discover more features.