
Angular Smart Table Component (DataTable)
Angular Smart Table provides a full set of features for displaying and manipulating tabular data. It allows you to easily create dynamic and interactive tables with features such as sorting, filtering, pagination, and searching. Angular Smart Table Component (DataTable) makes it easy to work with large datasets, and it is widely used in a variety of applications, including web-based applications, e-commerce sites, and more.
Features
- Filter items by one or all columns
- Sort items by column
- Integrated with CPagination component by default
- Customize style of specific rows, columns and cells
- Customize display of columns
- Load with initial filters and sorter state
- Loading state visualization
- Default header labels generation based on column names
Examples
Basic usage
Derick Maximinus | 2022/03/01 | Member | |||
Ebbe Gemariah | 2022/02/08 | Admin | |||
Enéas Kwadwo | 2022/03/01 | Member | |||
Estavan Lykos | 2022/02/01 | Staff | |||
Eustorgios Amulius | 2022/03/01 | Member | |||
Default header
- labels generation based on column names
10 | Agapetus Tadeáš | 2022/01/21 | Staff | Active |
11 | Carwyn Fachtna | 2022/01/01 | Member | Active |
12 | Nehemiah Tatius | 2022/02/11 | Staff | Banned |
13 | Ebbe Gemariah | 2022/02/08 | Admin | Inactive |
14 | Eustorgios Amulius | 2022/03/01 | Member | Pending |
15 | Leopold Gáspár | 2022/01/21 | Staff | Active |
16 | Pompeius René | 2022/01/10 | Member | Active |
17 | Paĉjo Jadon | 2022/02/01 | Staff | Banned |
18 | Micheal Mercurius | 2022/02/11 | Admin | Inactive |
19 | Ganesha Dubhghall | 2022/03/01 | Member | Pending |
Custom headers
- custom table header templates ~4.7.7
To add custom column header template with a labelTemplateName
:
- HTML: add
ng-template
withcTemplateId="columnLabel_
labelTemplateName
"
andlet-column
template variable - TypeScript: define
IColumns[]
config with_labelTemplateId
and optional_data
John Doe | Guest | Pending | 2022/01/01 |
Samppa Nori | Member | Active | 2022/01/31 |
Estavan Lykos | Staff | Banned | 2022/02/01 |
Chetan Mohamed | Admin | Inactive | 2022/02/01 |
Derick Maximinus | Member | Pending | 2022/03/01 |
Friderik Dávid | Staff | Active | 2022/01/21 |
Yiorgos Avraamu | Member | Active | 2022/01/07 |
Avram Tarasios | Staff | Banned | 2022/02/08 |
Quintin Ed | Admin | Inactive | 2022/02/01 |
Enéas Kwadwo | Member | Pending | 2022/03/01 |
Column groups
The Angular Smart Table component allows grouping related columns under a shared header. This feature is useful for presenting data categorized into groups or comparing different sets. The header group spans the width of the included columns and enhances organization and readability by grouping related data. Column groups can be nested and styled.
Agapetus Tadeáš | 2022/01/21 | Staff | Active |
Carwyn Fachtna | 2022/01/01 | Member | Active |
Nehemiah Tatius | 2022/02/11 | Staff | Banned |
Ebbe Gemariah | 2022/02/08 | Admin | Inactive |
Eustorgios Amulius | 2022/03/01 | Member | Pending |
Leopold Gáspár | 2022/01/21 | Staff | Active |
Pompeius René | 2022/01/10 | Member | Active |
Paĉjo Jadon | 2022/02/01 | Staff | Banned |
Micheal Mercurius | 2022/02/11 | Admin | Inactive |
Ganesha Dubhghall | 2022/03/01 | Member | Pending |
Custom filters
To filter a column with a columnName
:
- HTML: add
ng-template
withcTemplateId="columnFilter_
columnName
"
with your component - TypeScript: create
filterFunction
and pass it to thecolumnFilterValue
prop ofc-smart-table
component
Custom filter with MultiSelect
John Doe | Guest |
Samppa Nori | Member |
Estavan Lykos | Staff |
Chetan Mohamed | Admin |
Derick Maximinus | Member |
Friderik Dávid | Staff |
Yiorgos Avraamu | Member |
Avram Tarasios | Staff |
Quintin Ed | Admin |
Enéas Kwadwo | Member |
Custom filter with Date Range Picker
John Doe | 2022/01/01 |
Carwyn Fachtna | 2022/01/01 |
Vishnu Serghei | 2022/01/01 |
Aulus Agmundr | 2022/01/01 |
Yiorgos Avraamu | 2022/01/07 |
Pompeius René | 2022/01/10 |
Custom functions
Custom filter/sorter functions with nested data column
John Doe | France | Paris |
Samppa Nori | Chile | Santiago |
Estavan Lykos | Germany | Berlin |
Chetan Mohamed | Germany | Berlin |
Derick Maximinus | Chile | Santiago |
Friderik Dávid | France | Paris |
Yiorgos Avraamu | Chile | Concepción |
Avram Tarasios | Chile | Santiago |
Quintin Ed | France | Lyon |
Enéas Kwadwo | Chile | Santiago |
Custom filter/sorter functions with tableData
template aggregated columns
No items found |
Summary row
- Starting from ~4.5.26you can pass an ng-template with
cTemplateId="tableSummaryRow"
as a c-smart-table content. - Style
tr
andth
elements according to your needs. Display any data you want.
John Doe | 2022/01/01 | Guest | Pending | |
Samppa Nori | 2022/01/31 | Member | Active | |
Estavan Lykos | 2022/02/01 | Staff | Banned | |
Chetan Mohamed | 2022/02/01 | Admin | Inactive | |
Derick Maximinus | 2022/03/01 | Member | Pending | |
Selected: 0. | Items count: 25. |
External data
One of the key features of CoreUI Angular Smart Table (Angular DataTable) is the ability to load data from an external source, such as an API or a server-side script. This can be useful if you have a large amount of data that you don't want to load all at once, or if you want to allow users to interact with the data without having to reload the page.
Use the HttpClient
for communication with the data source, and get the external data from backend into a CoreUI Angular Smart Table (Angular DataTable).
Here is an example of how you might use CoreUI Angular Smart Table with external data (10.000+ records):
API
SmartTable Module
SmartTable Standalone
c-smart-table
component
Inputs
name | description | type | default |
---|---|---|---|
activePage |
Current page number | number |
1 |
cleaner |
Displays table cleaner above table. Cleaner resets tableFilterValue , columnFilterValue , sorterValue . If clean is possible it is clickable, otherwise it is not clickable and transparent. Cleaner can be customized through the cleaner slot. |
boolean |
false |
clickableRows |
Style table items as clickable. | boolean |
false |
columnFilter |
Displays additional filter row between table header and items, allowing filtering by specific column. | boolean | IColumnFilter |
undefined |
columnFilterValue |
Value of table filter. To set pass object where keys are column names and values are filter strings e.g.: { user: 'John', age: 12 } . |
IColumnFilterValue |
{ } |
columns |
(1) Table columns configuration. If not defined, table displays columns based on the first item keys, omitting keys that begins with underscore (e.g. '_classes') | (string | IColumn)[] |
undefined |
columnSorter |
(2) Enables table sorting by column value. Sorting will be performed correctly when values in a column are of one type: string (case insensitive) or number . |
boolean | ISorter |
undefined |
footer |
Displays table footer, which mirrors table header. (without column filter). | boolean |
false |
header |
Displays table header. | boolean |
false |
items |
(3) Array of objects, where each object represents one item - row in table. | IItem[] |
[] |
itemsPerPage |
Number of items per site, when pagination is enabled. | number |
10 |
itemsPerPageLabel |
Label for items per page selector. | string |
Items per page: |
itemsPerPageOptions |
Items per page selector options. | number[] |
[5, 10, 20, 50] |
itemsPerPageSelect |
Adds select element over table, which is used for control items per page in pagination. | boolean | ItemsPerPageSelect |
undefined |
loading |
When set, table will have loading style: loading spinner and reduced opacity. When 'small' prop is enabled spinner will be also smaller. | boolean |
undefined |
noItemsLabel |
String for passing custom noItemsLabel text. | string |
No items found |
pagination |
Enables default pagination. Default pagination will always have the computed number of pages that cannot be changed. The number of pages is generated based on the number of passed items and 'itemsPerPage' prop. If this restriction is an obstacle, you can make external pagination instead. | boolean |
false |
selectable |
Add checkboxes to make table rows selectable. | boolean |
false |
selectAll 4.5.26+ |
Enable / disable "select all" checkbox displayed in the header of the table. | boolean |
true |
sorterValue |
State of the sorter. Name key is column name, direction can be 'asc' or 'desc'. | ISorterValue |
{ } |
tableFilter |
(4) When set, displays table filter above table, allowing filtering by specific column. | boolean | ITableFilter |
undefined |
tableFilterLabel |
A label for a tableFilter input. | string |
Filter: |
tableFilterPlaceholder |
Specifies a short hint that is visible in the search input. | string |
Type string... |
tableFilterValue |
Value of table filter. | string |
'' |
tableBodyProps |
Properties for tbody | ITableGroupProps |
{ } |
tableFootProps |
Properties for tfoot. | ITableGroupProps |
{ } |
tableHeadProps |
Properties for thead. | ITableGroupProps |
{ } |
tableProps |
Properties for cTable. | ITable |
{ } |
(1) In columns
array each item represents one column. Item might be specified in two ways:
- String: each item define column name equal to item value.
- Object: item is object with following keys available as column configuration:
key
(required)(String) - define column name equal to item key.label
(String) - define visible label of column. If not defined, label will be generated automatically based on column name, by converting kebab-case and snake_case to individual words and capitalization of each word._classes
(String/Array/Object) - adds classes to all cells in a column_style
(String/Array/Object) - adds styles to the column header (useful for defining widths)_props
- (Object) - adds props for a column headersorter
(Boolean/CompareFn(a,b) => number) - disables sorting of the column when set to false. See also: CompareFnfilter
(Boolean/FilterFn(item, value: string) => boolean) - removes filter from column when set to false
(2) Sorter can be customized, by passing prop as object with additional options as keys. Available options:
- external (Boolean) - Disables automatic sorting inside component.
- resettable (Boolean) - If set to true, clicking on sorter have three states: ascending, descending and null. That means that third click on sorter will reset sorting, and restore table to original order.
(3) Example item:
{ name: 'John' , age: 12, _selectable: false, _props: { color: 'success' }, _cellProps: { age: { active: true, align: 'middle'}}}
For column generation description see columns prop.
(4) Column filter can be customized, by passing prop as object with additional options as keys. Available options:
- placeholder (String) - Sets custom table filter placeholder.
- label (String) - Sets custom table filter label.
- external (Boolean) - Disables automatic filtering inside component.
- lazy (Boolean) - Set to true to trigger filter updates only on change event.
Outputs
name | description | type | notes |
---|---|---|---|
activePageChange |
Event emitted on activePage change |
number |
|
cleanerClick |
Event emitted on cleaner click | v5.4.12+ | |
columnFilterValueChange |
Event emitted on columnFilterValue change |
||
filteredItemsChange |
Event emitted on filteredItems change |
||
itemsPerPageChange |
Event emitted on itemsPerPage change |
||
rowClick |
Event emitted on row click | ||
selectedItemsChange |
Event emitted on selectedItems change |
||
sorterValueChange |
Event emitted on sorterValue change |
||
tableFilterValueChange |
Event emitted on tableFilterValue change |
Templates
You can pass an ng-template with cTemplateId as a c-smart-table content.
Available templates with [cTemplateId] names:
tableCustomHeader
(~4.4.5goes to the header row with table filter/cleaner)tableData
(goes totd
html element for specifiedcolumnName
)tableDetails
(goes to separate row as row details, for everytr
)tableSummaryRow
(~4.5.26goes to the table footer)columnFilter_*
(see: Custom Filters)columnLabel_*
(~4.7.7see: Custom Headers)
All templates are optional.
To use custom templates you'll have to:
import {SharedModule} from '@coreui/angular'
- pass the template name as a string to
[cTemplateId]
directive
For tableData
pass the following variables:
columnName
('key' - derived from [columns] definition)item
(current row of [items] data array)tdContent
(default content for every column of a current row)
<ng-template cTemplateId="tableData" let-columnName="columnName" let-item="item" let-tdContent="tdContent" > ... </ng-template>
Having columnName you can ngSwitch
for custom rendering specified columns. Do not forget about ngSwitchDefault
with tdContent
.
Also - SmartTableComponent has exportAs: cSmartTable
that you can use as a template variable (#smartTable in the example)
- SharedModule - [cTemplateId]
- ButtonModule - [cButton]
- TableModule - [cTableActive], [cTableColor]
- UtilitiesModule - [cAlign]