When you create a custom data type and use the default bare layout, you can apply your own styles, align content in a column, configure text wrapping and clipping.
To support accessibility and keyboard navigation for a custom data type, use a slot for the custom data type. See Accessibility for Custom Data Types.
Apply Styles on a Column
To apply styling to all rows in a column, pass the CSS classes to cellAttributes in the column configuration.
To apply styling to particular rows, use the fieldName attribute to wire up the CSS classes to your data definition. This example uses the fieldName property industryClass to apply blue text to rows that are in the Energy industry.
Custom classes are currently not supported. To apply custom styling, use the SLDS utility classes. For example, apply text color using the SLDS text utility classes.
Align Content in a Custom Cell
You can align content in a column that uses the standard layout on a custom data type. In your cellAttributes definition, pass in the alignment property.
Supported alignment values are left, center, and right.
By default, standard number types align to the right. Standard number types include the currency, number, and percent data types.
Text Wrapping and Clipping
When you create a custom data type, implement the text wrapping and clipping with the SLDS utility classes slds-hyphenate and slds-truncate. These classes enable the custom data cell to display correctly when users change the wrap text selection in the datatable column header. Text wrapping expands the rows vertically to reveal more content. Text clipping truncates the content to a single line within the column.
Let’s say you have a custom data type template that displays account names. The column displays with the text clipped by default, which truncates content with a trailing ellipsis.
You can control how many lines are displayed when column content is wrapped. Set wrap-text-max-lines in your extended datatable component to display a number of lines before hiding the rest. The datatable applies line clamping to allow for multi-line text truncation.