Datatable
Datatables organize structured data into rows and columns with optional interactions.
Component variations
Basic Table
A simple datatable with basic columns and data
Name | Email | Status |
|---|---|---|
John Doe | ||
Jane Smith | ||
Bob Johnson |
Table with Pagination
Datatable with pagination controls
Name | Email | Status |
|---|---|---|
John Doe | ||
Jane Smith | ||
Bob Johnson |
Table with Pagination and Row Counts
Datatable with pagination controls and row counts
Name | Email | Status |
|---|---|---|
John Doe | ||
Jane Smith | ||
Bob Johnson |
Expandable Table
Datatable with expandable rows for additional details
Name | Email | Status |
|---|---|---|
John Doe | ||
Jane Smith | ||
Bob Johnson |
Table with actions
Datatable with actions for each row
Name | Email | Status | Actions |
|---|---|---|---|
John Doe | |||
Jane Smith | |||
Bob Johnson |
Usage Guidelines
Import
Import the datatable component and interfaces in your module or component:
import-datatable.ts
Copy code
Basic Implementation
Here is a basic example of using the datatable component:
1. Define data
my.component.ts
Copy code
2. Implementation in template
my.component.html
Copy code
Implementation with Custom Templates
Using custom templates for dynamic cell rendering (e.g., status badges):
1. Define TemplateRef and columns in TypeScript
my.component.ts
Copy code
2. Create template and use in datatable
my.component.html
Copy code
Expandable Rows Implementation
Enable expandable rows to display additional details when a row is clicked:
1. Define expandable columns in TypeScript
my.component.ts
Copy code
2. Use expandable in template
my.component.html
Copy code
Pagination Implementation
Add pagination controls with row counters to navigate through large datasets:
1. Define pagination state in TypeScript
my.component.ts
Copy code
2. Use pagination in template
my.component.html
Copy code
Actions Implementation
Add action buttons for each row with conditional visibility and disabled states:
1. Define actions in TypeScript
my.component.ts
Copy code
2. Use actions in template
my.component.html
Copy code
API Reference
Inputs
Property | Type | Default | Required | Description |
|---|---|---|---|---|
T[] | [] | Yes | Array of data objects to display in the table | |
VdDatatableColumn[] | [] | Yes | Array of column definitions for the table | |
VdDatatableColumn[] | [] | No | Columns to show when a row is expanded | |
VdDatatableAction[] | [] | No | Array of action buttons to show for each row | |
boolean | false | No | Whether rows can be expanded to show additional details | |
number | 1 | No | Current page number for pagination | |
number | 0 | No | Total number of pages (if 0, pagination is hidden) | |
number | 10 | No | Number of rows to display per page | |
number | 0 | No | Total number of rows in the dataset |
Outputs
Event emitters for table interactions:
Property | Type | Description |
|---|---|---|
EventEmitter<number> | Emitted when the page changes | |
EventEmitter<T> | Emitted when a row is clicked | |
EventEmitter<{ action: string; row: T }> | Emitted when an action button is clicked |
Best Practices
When to Use
- Use Datatable when this pattern clearly supports the user task.
- Use it to keep similar interactions consistent across the product.
When Not to Use
- Avoid using Datatable when a simpler component communicates the same intent.
- Avoid using it when the pattern introduces unnecessary interaction steps.
Design Guidelines
- Use meaningful column titles that clearly describe the data
- Limit columns to 5-7 for optimal readability on most screens
- Enable pagination when displaying more than 20 rows to improve performance
- Use expandable rows for detailed information that doesn't fit in a single row
- Provide clear action buttons with icons and tooltips
- Sort and filter data on the client side for better user experience
- Use custom templates for complex cell content like badges or status indicators
- Always specify totalPages and totalRows for accurate pagination display
- Keep labels, helper text, and actions concise and easy to scan.
- Use VD variants and states consistently for predictable behavior.
- Ensure keyboard access and clear focus order for accessibility.
Component playground
Customize the datatable features in this section
Name | Email | Status |
|---|---|---|
John Doe | ||
Jane Smith | ||
Bob Johnson |
example.html
Copy code