On this page
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.
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
~4.7.7
To add custom column header template with a *`labelTemplateName`*:
1. HTML: add `ng-template` with `cTemplateId="columnLabel_`*`labelTemplateName`*`"` and `let-column` template variable
2. TypeScript: define `IColumns[]` config with `_labelTemplateId` and optional `_data`
---
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
~5.2.19
---
Loading...
Loading...
Loading...
Loading...
~4.5.26
you can pass an ng-template with `cTemplateId="tableSummaryRow"` as a c-smart-table content.
- Style `tr` and `th` elements according to your needs. Display any data you want.
---
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
| 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`
---
(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 header
- `sorter` (Boolean/CompareFn(a,b) => number) - disables sorting of the column when set to false. See also: CompareFn
- `filter` (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
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` | _{ }_ |
| name | description | type |
| ---- | ----------- | ---- |
| `activePageChange` | Event emitted on `activePage` change | `number` |
| `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.5
goes to the header row with table filter/cleaner)
- `tableData` (goes to `td` html element for specified `columnName`)
- `tableDetails` (goes to separate row as row details, for every `tr`)
- `tableSummaryRow` ( ~4.5.26
goes to the table footer)
- `columnFilter_*` (see: [Custom Filters](components/smart-table#custom-filters))
- `columnLabel_*` (~4.7.7
see: [Custom Headers](components/smart-table#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)
```html
<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]