lightning-datatable with custom data types to render specialized content in table cells.
Overview
This example demonstrates how to:- Create a custom datatable by extending
LightningDatatable - Define custom column types with custom templates
- Register type attributes for data binding
- Display custom content (contact pictures) in table cells
Component Structure
Custom Datatable Component
Create a custom datatable class that extendsLightningDatatable:
customDataTypes.js
Custom Type Template
Define the HTML template for rendering the custom type:customPicture.html
Usage
Column Definitions
Define columns with the custom data type:datatableCustomDataType.js
Template
Use your custom datatable component instead oflightning-datatable:
datatableCustomDataType.html
Custom Type Configuration
Properties
| Property | Type | Description |
|---|---|---|
template | HTMLTemplateElement | The HTML template to render for this type |
standardCellLayout | Boolean | Whether to use standard cell padding and layout |
typeAttributes | String[] | Array of attribute names available in the template |
Type Attributes
Type attributes allow passing data from the column definition to the custom template:Use Cases
- Custom Visualizations: Display charts, graphs, or images in cells
- Rich Content: Render formatted text, badges, or icons
- Interactive Elements: Add buttons or links with custom behaviors
- Domain-Specific Types: Create types for ratings, progress bars, or status indicators
Related Components
Source
datatableCustomDataType.js:4-18- Column definitions with custom typecustomDataTypes.js:1-12- Custom datatable classcustomPicture.html:1-7- Custom type template
