Angular Table Directives
Documentation and examples for opt-in styling of Angular tables.
Examples
Using the most basic table CoreUI, here's howcTable
based tables look in CoreUI.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Variants
Use contextual classes to color tables, table rows or individual cells.
Class | Heading | Heading |
---|---|---|
Default | Cell | Cell |
Primary | Cell | Cell |
Secondary | Cell | Cell |
Success | Cell | Cell |
Danger | Cell | Cell |
Warning | Cell | Cell |
Info | Cell | Cell |
Light | Cell | Cell |
Dark | Cell | Cell |
Striped rows
Usestriped
property to add zebra-striping to any table row within thetbody
.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Striped columns
UsestripedColumns
property to add zebra-striping to any table column.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Usecolor
property to add some color variants.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Hoverable rows
Usehover
property to enable a hover state on table rows within atbody
.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
These hoverable rows can also be combined with thestriped
variant:
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Active tables
Highlight a table row or cell by adding acTableActive
property.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
import { Component } from '@angular/core';import { TableActiveDirective, TableDirective } from '@coreui/angular';@Component({ selector: 'docs-table08', templateUrl: './table08.component.html', standalone: true, imports: [TableDirective, TableActiveDirective]})export class Table08Component {}
Bordered tables
Addbordered
property for borders on all sides of the table and cells.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Border color utilities can be added to change colors:
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Borderless
Addborderless
property for a table without borders.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Small tables
Addsmall
property to make anycTable
more compact by cutting all cellpadding
in half.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Vertical alignment
Table cells ofthead
are always vertical aligned to thebottom. Table cells intbody
inherit their alignment fromcTable
and are aligned to the the top by default. Use the alignproperty to re-align where needed.
Heading 1 | Heading 2 | Heading 3 | Heading 4 |
---|---|---|---|
This cell inheritsvertical-align: middle; from the table | This cell inheritsvertical-align: middle; from the table | This cell inheritsvertical-align: middle; from the table | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
This cell inheritsvertical-align: bottom; from the table row | This cell inheritsvertical-align: bottom; from the table row | This cell inheritsvertical-align: bottom; from the table row | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonstrate how the vertical alignment works in the preceding cells. |
This cell inheritsvertical-align: middle; from the table | This cell inheritsvertical-align: middle; from the table | This cell is aligned to the top. | This here is some placeholder text, intended to take up quite a bit of vertical space, to demonsCTableRowate how the vertical alignment works in the preceding cells. |
Nesting
Border styles, active styles, and table variants are not inherited by nested tables.
# | Class | Heading | Heading | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Mark | Otto | @mdo | ||||||||||||
| |||||||||||||||
3 | Larry the Bird |
Table head
Similar to tables and dark tables, use the modifier propcolor="light"
orcolor="dark"
to makethead
appear light or dark gray.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry | the Bird |
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird |
Table foot
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry the Bird | ||
Footer | Footer | Footer | Footer |
Captions
Acaption
functions like a heading for a table. It helps users with screen readers to find a table and understand what it's about and decide if they want to read it.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry | the Bird |
You can also put a caption on the top of the table withcaption="top"
.
# | Class | Heading | Heading |
---|---|---|---|
1 | Mark | Otto | @mdo |
2 | Jacob | Thornton | @fat |
3 | Larry | the Bird |
Responsive tables
Always responsive
Responsive tables allow tables to be scrolled horizontally with ease.Make any table responsive across all viewports by adding aresponsive
property.
# | Heading | Heading | Heading | Heading | Heading | Heading | Heading | Heading |
---|---|---|---|---|---|---|---|---|
1 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
2 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
3 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
Breakpoint specific
Or pick a maximum breakpoint with which to have a responsive table up to by usingresponsive="sm|md|lg|xl|xxl"
.
# | Heading | Heading | Heading | Heading | Heading | Heading | Heading | Heading |
---|---|---|---|---|---|---|---|---|
1 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
2 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
3 | Cell | Cell | Cell | Cell | Cell | Cell | Cell | Cell |
API reference
Table Module
import { TableModule, UtilitiesModule } from '@coreui/angular';@NgModule({ imports: [ TableModule, UtilitiesModule ]})export class AppModule() { }
cTable
directive fortable
element
Inputs:
prop | type | default | description |
---|---|---|---|
align | Alignments | undefined | table cells vertical alignment |
borderColor | Colors | undefined | border color for bordered table |
bordered | boolean | undefined | adds borders on all sides of the table and cells |
borderless | boolean | undefined | for a table without borders at all |
caption | top | undefined | putscaption on the top of the table |
color | Colors | undefined | sets color of whole table |
hover | boolean | undefined | enable a hover state on table rows within atbody |
responsive | boolean / breakpoint | undefined | adds responsive wrapper to table or pick a maximum breakpoint |
small | boolean | undefined | makes compact table by cutting all cell padding in half |
striped | boolean | undefined | adds striping to any table row within thetbody |
stripedColumns | boolean | undefined | adds striping to any table column |
cTableActive
directive fortr
ortd
elements
Inputs:
prop | type | default | description |
---|---|---|---|
cTableActive | boolean | undefined | add highlight to rowtr or celltd |
cTableColor
directive fortable
,thead
,th
,tbody
,tfoot
tr
ortd
elements
Input:
prop | type | default | description |
---|---|---|---|
cTableColor | Colors | undefined | add color tables, rows or individual cells |
cAlign
directive fortable
,thead
,th
,tbody
,tfoot
tr
ortd
elements
Input:
prop | type | default | description |
---|---|---|---|
cAlign | top bottom middle | undefined | vertical alignment for cellstable ,tr ortd |