Movatterモバイル変換


[0]ホーム

URL:


CoreUI Angular Logo
Framework:
Getting startedIntroductionSupport CoreUICustomizeSassOptionsCSS VariablesLayoutBreakpointsContainersGridColumnsGuttersFormsOverviewAutocompletePRODate PickerPRODate Range PickerPROForm ControlSelectMulti SelectPROChecks & RadiosPassword InputPRORangeRange SliderPRORatingPROStepperPROInput GroupFloating LabelsLayoutTime PickerPROValidationComponentsAccordionAlertAvatarBadgeBreadcrumbButtonButton GroupCalendarPROCalloutCardCarouselClose buttonCollapseDropdownFooterHeaderImageList GroupLoading ButtonPROModalNavNavbarOffcanvasPaginationPlaceholderPopoverProgressSmart PaginationPROSmart TablePROSidebarSpinnerTableTabsNewToastTooltipWidgetsIconsChartsTemplatesNewAdmin & DashboardDownloadInstallationCustomizeContentMigrationv4 → v5v3 → v4Angular version


DownloadHire UsGet CoreUI PRO
On this page
CoreUI PRO for Angular This component is part of CoreUI PRO – a powerful UI library with over 250 components and 25+ templates, designed to help you build modern, responsive apps faster. Fully compatible with Angular, Bootstrap, React.js, and Vue.js. Get CoreUI PRO

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

Name
Registered
Role
Status
Derick Maximinus 2022/03/01 Member Pending
Derick Maximinus

User since: 2022/03/01

Ebbe Gemariah 2022/02/08 Admin Inactive
Ebbe Gemariah

User since: 2022/02/08

Enéas Kwadwo 2022/03/01 Member Pending
Enéas Kwadwo

User since: 2022/03/01

Estavan Lykos 2022/02/01 Staff Banned
Estavan Lykos

User since: 2022/02/01

Eustorgios Amulius 2022/03/01 Member Pending
Eustorgios Amulius

User since: 2022/03/01

Name
Registered
Role
Status
Loading...
Loading...
Loading...

Default header

  • labels generation based on column names

Id
Name
Registered
Role
Status
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
Loading...
Loading...

Custom headers

  • custom table header templates
    ~4.7.7

To add custom column header template with alabelTemplateName:

  1. HTML: addng-template withcTemplateId="columnLabel_labelTemplateName" andlet-column template variable
  2. TypeScript: defineIColumns[] config with_labelTemplateId and optional_data

Name
Role
Status
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
Loading...
Loading...

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.


Main Group
Subgroup 1 Subgroup 2
Long and overflowing header label caption
Registered
Role
Status
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
Loading...
Loading...

Custom filters

To filter a column with acolumnName :

  1. HTML: addng-template withcTemplateId="columnFilter_columnName" withyour component
  2. TypeScript: createfilterFunction and pass it to thecolumnFilterValue prop ofc-smart-table component
Custom filter with MultiSelect

Name
Role
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
Loading...
Loading...

Custom filter with Date Range Picker

Name
Registered
Mon
Tue
Wed
Thu
Fri
Sat
Sun
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
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
Loading...
Loading...

Custom functions

Custom filter/sorter functions with nested data column

Name
Address
City
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
Loading...
Loading...
Loading...

Custom filter/sorter functions withtableData template aggregated columns
~5.2.19


User
Country
Email
No items found
Loading...

Loading...
Loading...
Loading...

Summary row

  • Starting from
    ~4.5.26
    you can pass an ng-template withcTemplateId="tableSummaryRow" as a c-smart-table content.
  • Styletr andth elements according to your needs. Display any data you want.

Name
Registered
Role
Status
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.
Loading...
Loading...
Loading...

External data

One of the key features ofCoreUI 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 theHttpClient for communication with the data source, andget 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):

Loading...
Loading...
Loading...

API

SmartTable Module

SmartTable Standalone


c-smart-table

component

Inputs

namedescriptiontypedefault
activePageCurrent page numbernumber1
cleanerDisplays table cleaner above table. Cleaner resetstableFilterValue,columnFilterValue,sorterValue. If clean is possible it is clickable, otherwise it is not clickable and transparent. Cleaner can be customized through the cleaner slot.booleanfalse
clickableRowsStyle table items as clickable.booleanfalse
columnFilterDisplays additional filter row between table header and items, allowing filtering by specific column.boolean | IColumnFilterundefined
columnFilterValueValue 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) ornumber.boolean | ISorterundefined
footerDisplays table footer, which mirrors table header. (without column filter).booleanfalse
headerDisplays table header.booleanfalse
items(3) Array of objects, where each object represents one item - row in table.IItem[][]
itemsPerPageNumber of items per site, when pagination is enabled.number10
itemsPerPageLabelLabel for items per page selector.stringItems per page:
itemsPerPageOptionsItems per page selector options.number[][5, 10, 20, 50]
itemsPerPageSelectAdds select element over table, which is used for control items per page in pagination.boolean | ItemsPerPageSelectundefined
loadingWhen set, table will have loading style: loading spinner and reduced opacity. When 'small' prop is enabled spinner will be also smaller.booleanundefined
noItemsLabelString for passing custom noItemsLabel text.stringNo items found
paginationEnables 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.booleanfalse
selectableAdd checkboxes to make table rows selectable.booleanfalse
selectAll
4.5.26+
Enable / disable "select all" checkbox displayed in the header of the table.booleantrue
sorterValueState 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 | ITableFilterundefined
tableFilterLabelA label for a tableFilter input.stringFilter:
tableFilterPlaceholderSpecifies a short hint that is visible in the search input.stringType string...
tableFilterValueValue of table filter.string''
tableBodyPropsProperties for tbodyITableGroupProps{ }
tableFootPropsProperties for tfoot.ITableGroupProps{ }
tableHeadPropsProperties for thead.ITableGroupProps{ }
tablePropsProperties for cTable.ITable{ }

(1) Incolumns 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

namedescriptiontypenotes
activePageChangeEvent emitted onactivePage changenumber
cleanerClickEvent emitted on cleaner clickv5.4.12+
columnFilterValueChangeEvent emitted oncolumnFilterValue change
filteredItemsChangeEvent emitted onfilteredItems change
itemsPerPageChangeEvent emitted onitemsPerPage change
rowClickEvent emitted on row click
selectedItemsChangeEvent emitted onselectedItems change
sorterValueChangeEvent emitted onsorterValue change
tableFilterValueChangeEvent emitted ontableFilterValue 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 totd html element for specifiedcolumnName)
  • tableDetails (goes to separate row as row details, for everytr)
  • tableSummaryRow (
    ~4.5.26
    goes to the table footer)
  • columnFilter_*(see:Custom Filters)
  • columnLabel_*(
    ~4.7.7
    see: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

FortableData 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 canngSwitch for custom rendering specified columns. Do not forget aboutngSwitchDefault withtdContent.

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]

CoreUI for Angular is Open Source UI Components Library for Angular.

Currently v5.5.17 Code licensed MIT, docs CC BY 3.0 .
CoreUI PRO requires acommercial license.


[8]ページ先頭

©2009-2025 Movatter.jp