Table
The Table component uses HTML's native table element. It allows tabular data to be displayed in a responsive way with special case cells.
Examples
Base
Each row is represented as an object in an array passed to the data
prop.
Customise
Define the table in the way that you need it to be.
Columns
Columns can either be defined by adding <o-table-column>
components to the default
slot, or by adding an array to the columns
prop, where each object defines a column. It is possible to mix both approaches by adding a columns
prop as well as passing <o-table-column>
components in the before
or after
slots.
Selection
When the selectable
prop is set, the selected
prop represents the currently selected element. The prop is two-way bindable.Consider defining whether a row is selectable with a function given by the is-row-selectable
prop.
Checkable
When the checkable
prop is set, each row will have a checkbox. The checkbox position can be changed from left to right using the checkbox-position
prop. The checked rows are combined in the checked-rows
prop, which is two-way bindable. Consider defining whether a row is checkable with a function given by the is-row-checkable
prop.
Detailed
Each row can have a collapse section by adding the detailed
prop. The rows with an open detail section are combined in the detailed-rows
prop, which is two-way bindable. By default, the detail is displayed as another tr, but adding custom-detail-row
removes the tr wrapper from the provided detail
slot. Consider defining whether a row can have a detail section with a function given by the is-detailed-visibile
prop.
Pagination
The table component uses the pagination component when the paginated
prop is set. The per-page
prop can be used to specify the number of rows per page. Any property prefixed with "pagination" is passed to the pagination component.
Searchable
Columns can have a search filter input by adding searchable
to the TableColumn component item. The search filter can be debounced to avoid multiple filtering when typing wich adding the filter-debounce
prop to the Table component.
Async Data
Every data-related function supports asynchronous loading behaviour. Consider adding backend-pagination
, backend-sorting
and backend-filtering
in addition to the required normal props to prevent the component from handling the events. Each functionality fires an event that can be used to update the data
. A loading state can also be enabled by using the loading
prop.
Sticky
Adding the sticky-header
prop to the Table component makes the header stick to the top when scrolling vertically. Adding the sticky
prop to individual TableColumn components makes the column stick to the left when scrolling horizontally.
Draggable rows/columns
Use draggable
/draggable-column
prop to allow rows and columns to be draggable. Manage dragging using dragstart
/columndragstart
, dragover
/columndragover
and drop
/columndrop
events.
Table component
Tabulated data are sometimes needed, it's even better when it's responsive.
<o-table></o-table>
Props
Prop name | Description | Type | Values | Default |
---|---|---|---|---|
ariaCurrentLabel | Accessibility label for the pagination current page button. | string | - | From config: table: { |
ariaNextLabel | Accessibility label for the pagination next page button. | string | - | From config: table: { |
ariaPageLabel | Accessibility label for the pagination page button. | string | - | From config: table: { |
ariaPreviousLabel | Accessibility label for the pagination previous page button. | string | - | From config: table: { |
backendFiltering | Columns won't be filtered on clientside, use with searchable prop to the columns to filter in your backend | boolean | - | From config: table: { |
backendPagination | Rows won't be paginated on clientside, use with page-change event to paginate in your backend | boolean | - | false |
backendSorting | Columns won't be sorted on clientside, use with sort event to sort in your backend | boolean | - | From config: table: { |
bordered | Border to all cells | boolean | - | From config: table: { |
checkable | Rows can be checked (multiple) | boolean | - | false |
checkableHeader | Show check/uncheck all checkbox in table header when checkable (if checkable) | boolean | - | true |
checkboxPosition | Position of the checkbox when checkable (if checkable) | "left" | "right" | left , right | From config: table: { |
checkboxVariant | Color of the checkbox when checkable (if checkable) | string | primary , info , success , warning , danger , and any other custom color | From config: table: { |
checkedRows | Set which rows are checked, use v-model:checkedRows to make it two-way binding (if checkable) | unknown[] | - | [] |
columns | Table columns | TableColumn<unknown>[] | - | |
currentPage | Current page of table data (if paginated), use v-model:currentPage to make it two-way binding | number | - | 1 |
customCompare | Define a custom comparison function to check whether two row elements are equal. By default a rowKey comparison is performed if given. Otherwise a simple object comparison is done. | ((a: unknown, b: unknown) => boolean) | - | |
customDetailRow | Enable custom style on details (if detailed) | boolean | - | false |
data | Table data | unknown[] | - | |
defaultSort | Sets the default sort column and order — e.g. 'first_name' or ['first_name', 'desc'] | 'desc'] | [string, 'asc' | string | - | From config: table: { |
defaultSortDirection | Sets the default sort column direction on the first click | 'asc'|'desc' | asc , desc | From config: table: { |
detailIcon | Icon name of detail action (if detailed) | string | - | From config: table: { |
detailTransition | string | - | From config: table: { | |
detailed | Allow row details | boolean | - | false |
detailedRows | Set which rows have opened details, use v-model:detailedRows to make it two-way binding (if detailed).Ideal to open details via vue-router. (A unique key is required; check rowKey prop) | unknown[] | - | [] |
draggable | Allows rows to be draggable | boolean | - | false |
draggableColumn | Allows columns to be draggable | boolean | - | false |
emptyIcon | Icon to be shown when the table is empty | string | - | From config: table: { |
emptyIconSize | Size of empty icon | string | small , medium , large | From config: table: { |
emptyLabel | Label to be shown when the table is empty | string | - | From config: table: { |
filterDebounce | Filtering debounce time (in milliseconds) | number | - | From config: table: { |
filtersEvent | Add a native event to filter | string | - | "" |
filtersIcon | Icon of the column search input | string | - | From config: table: { |
filtersPlaceholder | Placeholder of the column search input | string | - | From config: table: { |
height | Table fixed height | number | string | - | |
hoverable | Rows are highlighted when hovering | boolean | - | From config: table: { |
iconPack | Icon pack to use | string | mdi , fa , fas and any other custom icon pack | From config: table: { |
isDetailedVisible | Controls the visibility of the trigger that toggles the detailed rows (if detailed) | ((row: unknown) => boolean) | - | From config: table: { |
isRowCheckable | Custom method to verify if a row is checkable (if checkable) | ((row: unknown) => boolean) | - | From config: table: { |
isRowChecked | Custom method to verify if a row is checked (if checkable) | ((row: unknown) => boolean) | - | |
isRowSelectable | Custom method to verify if a row is selectable, works when is selectable | ((row: unknown) => boolean) | - | true |
loading | Enable loading state | boolean | - | false |
loadingIcon | Icon for the loading state | string | - | From config: table: { |
loadingLabel | Label for the loading state | string | - | From config: table: { |
mobileBreakpoint | Mobile breakpoint as max-width value | string | - | From config: table: { |
mobileCards | Rows appears as cards on mobile (collapse rows) | boolean | - | From config: table: { |
mobileSortPlaceholder | Select placeholder text when nothing is selected (if mobileCards) | string | - | From config: table: { |
narrowed | Makes the cells narrower | boolean | - | From config: table: { |
override | Override existing theme classes completely | boolean | - | |
paginated | Adds pagination to the table | boolean | - | From config: table: { |
paginationOrder | Pagination buttons order (if paginated) | "centered" | "left" | "right" | centered , right , left | From config: table: { |
paginationPosition | Pagination position (if paginated) | "both" | "bottom" | "top" | bottom , top , both | From config: table: { |
paginationRounded | Enable rounded pagination buttons (if paginated) | boolean | - | From config: table: { |
paginationSimple | Enable simple style pagination (if paginated) | boolean | - | From config: table: { |
paginationSize | Size of pagination (if paginated) | string | small , medium , large | From config: table: { |
perPage | How many rows per page (if paginated) | number | string | - | From config: table: { |
rowKey | Use a unique key of your data Object for each row. Useful if your data prop has dynamic indices. (id recommended) | string | - | From config: table: { |
scrollable | Add a horizontal scrollbar when table is too wide | boolean | - | |
selectable | Table can be focused and user can select rows. Rows can be navigate with keyboard arrows and are highlighted when hovering. | boolean | - | From config: table: { |
selected | Set which row is selected, use v-model:selected to make it two-way binding (if selectable) | unknown | - | |
showDetailIcon | Allow detail icon and column to be visible (if detailed) | boolean | - | From config: table: { |
showHeader | Show header | boolean | - | From config: table: { |
sortIcon | Sets the header sorting icon | string | - | From config: table: { |
sortIconSize | Sets the size of the sorting icon | string | small , medium , large | From config: table: { |
stickyCheckbox | Make the checkbox column sticky (if checkable) | boolean | - | false |
stickyHeader | Show a sticky table header | boolean | - | false |
striped | Whether table is striped | boolean | - | From config: table: { |
tdAttrs | Adds native attributes to column td element of a row | ((row: unknown, column: TableColumn<unknown>) => object) | - | |
thAttrs | Adds native attributes to a column th element | ((column: TableColumn<unknown>) => object) | - | |
total | Total number of table data if backend-pagination is enabled | number | - | 0 |
Events
Event name | Properties | Description |
---|---|---|
page-change | page number - updated page | on pagination page change event |
dblclick | row T - row dataindex number - index of clicked rowevent Event - native click event | on row double click event |
mouseenter | row T - row dataindex number - index of clicked rowevent Event - native mouseenter event | on row mouseenter event |
mouseleave | row T - row dataindex number - index of clicked rowevent Event - native mouseleave event | on row mouseleave event |
contextmenu | row T - row dataindex number - index of clicked rowevent Event - native contextmenu event | on row right click event |
cell-click | row T - row datacolumn TableColumn - column dataindex number - row indexcolindex number - column indexevent Event - native click event | on cell click event |
update:currentPage | value number - updated currentPage prop | currentPage prop two-way binding |
update:selected | value T - updated select prop | select prop two-way binding |
select | newRow T - new select valueoldRow T - old select value | on row select event |
check | value T[] - all checked rowsrow T - row data | on row checked event |
check-all | value T[] - all checked rows | on all rows checked event |
update:checkedRows | value T[] - updated checkedRows prop | checkedRows prop two-way binding |
sort | column TableColumn - column datadirection string - 'asc' or 'desc'event Event - native event | on column sort change event |
filters-change | filters object - filter object | on filter change event |
filters-event | filtersEvent string - props filtersEvent valuefilters object - filter objectevent Event - native event | on native filter event based on props filtersEvent |
update:detailedRows | value T[] - updated detailedRows prop | detailedRows prop two-way binding |
details-open | row T - row data | on details open event |
details-close | row T - row data | on details close event |
click | row T - row dataindex number - index of clicked rowevent Event - native click event | on row click event |
dragstart | row T - row dataindex number - index of draged rowevent DragEvent - native dragstart event | on row dragstart event |
dragend | row T - row dataindex number - index of draged rowevent DragEvent - native dragend event | on row dragend event |
drop | row T - row dataindex number - index of draged rowevent DragEvent - native drop event | on row drop event |
dragleave | row T - row dataindex number - index of draged rowevent DragEvent - native dragleave event | on row dragleave event |
dragover | row T - row dataindex number - index of draged rowevent DragEvent - native dragover event | on row dragover event |
columndragstart | column TableColumn - column dataindex number - index of draged columnevent DragEvent - native columndragstart event | on column columndragstart event |
columndragend | column TableColumn - column dataindex number - index of draged columnevent DragEvent - native columndragend event | on column columndragend event |
columndrop | column TableColumn - column dataindex number - index of draged columnevent DragEvent - native columndrop event | on column columndrop event |
columndragleave | column TableColumn - column dataindex number - index of draged columnevent DragEvent - native columndragleave event | on column columndragleave event |
columndragover | column TableColumn - column dataindex number - index of draged columnevent DragEvent - native columndragover event | on column columndragover event |
Slots
Name | Description | Bindings |
---|---|---|
default | Place o-table-column here | |
before | Place extra o-table-column components here, even if you have some columns defined by prop | |
after | Place extra o-table-column components here, even if you have some columns defined by prop | |
pagination | Override pagination label | current number - current pageper-page number - rows per pagetotal number - total rows countchange (page: number): void - on page change event |
top-left | Additional slot if table is paginated | |
caption | Define a table caption here | |
preheader | Define preheader content here | |
check-all | Override check all checkbox | is-all-checked boolean - if all rows are checkedis-all-uncheckable boolean - if check all is uncheckablecheck-all (): void - check all function |
subheading | ||
detail | Place row detail content here | row T - row contentindex number - row index |
empty | Define content if table is empty | |
footer | Define a custom footer | column-count number - counts of visible columnsrow-count number - counts of visible rows |
loading | Override loading component | loading boolean - is loading state enabled |
bottom-left | Additional slot if table is paginated |
TableColumn component
Define a column used by the table component.
<o-table-column></o-table-column>
Props
Prop name | Description | Type | Values | Default |
---|---|---|---|---|
customSearch | Define a custom filter funtion for the search | ((row: unknown, filter: string) => boolean) | - | |
customSort | Define a custom sort function | ((a: unknown, b: unknown, isAsc: boolean) => number) | - | |
field | Define an object property key if data is an object | string | - | |
formatter | Provide a formatter function to edit the output | ((value: unknown, row: unknown) => string) | - | |
headerSelectable | Make header selectable | boolean | - | false |
hidden | Define whether the column is visible or not | boolean | - | false |
label | Define the column label | string | - | |
numeric | Define column value as number | boolean | - | false |
position | Position of the column content | "centered" | "left" | "right" | left , centered , right | |
searchable | Enable an additional searchbar below the column header | boolean | - | false |
sortable | Enable column sortability | boolean | - | false |
sticky | Whether the column is sticky or not | boolean | - | false |
subheading | Define a column sub heading | string | - | |
tdAttrs | Adds native attributes to td | object | - | |
thAttrs | Adds native attributes to th | object | - | |
width | Column fixed width | number | string | - |
Slots
Name | Description | Bindings |
---|---|---|
default | Default Slot | row T - row datacolumn TableColumn - column definitionindex number - row indexcolindex number - column indextoggle-details (): void - toggle details function |
header | Override header label | column TableColumn - column definitionindex number - column index |
subheading | Override subheading label | column TableColumn - column definitionindex number - column index |
searchable | Override searchable input | column TableColumn - column definitionindex number - column indexfilters object - active filters object |
Class Inspector
Class prop | Description | Props | Suffixes | |
---|---|---|---|---|
rootClass | Class of the root element. | |||
mobileClass | Class of the root and wrapper element when on mobile. 👉 Switch to mobile view to see it in action! | |||
mobileSortClass | Class of the sortable form wrapper on mobile. 👉 Switch to mobile view to see it in action! | |||
wrapperClass | Class of the table wrapper element. | |||
stickyHeaderClass | Class of the table wrapper element when header is sticky. | stickyHeader | ||
scrollableClass | Class of the table wrapper element when its content is scrollable. | scrollable | ||
tableClass | Class of the table element. | |||
borderedClass | Class of the table element when bordered. | bordered | ||
stripedClass | Class of the table element when striped. | striped | ||
narrowedClass | Class of the table element when narrowed. | narrowed | ||
hoverableClass | Class of the table element when hoverable. | hoverable | ||
emptyClass | Class of the table element when it is empty. | |||
thClass | Class of the table `th` element. | |||
thPositionClass | Class of the table `th` element with position. | position | left | |
thCheckboxClass | Class of the table `th` element when checkable. | checkable | ||
thStickyClass | Class of the table `th` element when checkbox is sticky. | stickyCheckbox | ||
thDetailedClass | Class of the table `th` element of the detail column of triggers. | detailed | ||
thSortableClass | Class of the table `th` element when sortable. | sortable | ||
thSortIconClass | Class of the table header sort icon element. 👉 Click on 'First Name' header to sort elements and see it in action! | |||
thCurrentSortClass | Class of the table `th` element that is currently sorted. 👉 Click on 'First Name' header to sort elements and see it in action! | |||
thUnselectableClass | Class of the Table `th` element that is unsortable. | headerSelectable | ||
thSubheadingClass | Class of the table `th` subheading element. | subheading | ||
trSelectedClass | Class of the table `tr` element when selected. 👉 Select a row of the table to see it in action! | |||
trDetailedClass | Class of the table `tr` element when detailed. . 👉 Expand details to see it in action! | detailed | ||
trCheckedClass | Class of the table `tr` element when checkable and checked. 👉 Select a row of the table to see it in action! | checkable | ||
trEmptyClass | Class of the table `tr` element when table is empty. | |||
tdClass | Class of the Table `td` element. | |||
tdPositionClass | Class of the table `td` element with position. | position | left | |
tdStickyClass | Class of the table `td` element when column is sticky. | sticky | ||
tdCheckboxClass | Class of the table `td` element when row is checkable. | checkable | ||
tdDetailedChevronClass | Class of the table `td` element that contains the chevron to trigger details. | detailed | ||
paginationWrapperClass | Class of the table pagination wrapper element. | paginated | ||
footerClass | Class of the table footer element. | |||
loadingClasses | Classes to apply on the internal loading component. More details here. |
Sass variables
Current theme ➜ Oruga
SASS Variable | Default |
---|---|
$table-background-color | #fff |
$table-background | #f5f5f5 |
$table-boder | 1px solid transparent |
$table-border-radius | var(--#{$prefix}base-border-radius) |
$table-card-box-shadow | 0 2px 3px rgba(var(--#{$prefix}black), 0.1), 0 0 0 1px rgba(var(--#{$prefix}black), 0.1) |
$table-card-cell-font-weight | 600 |
$table-card-cell-padding | 0 0.5em 0 0 |
$table-card-cell-text-align | left |
$table-card-detail-margin | -1rem 0 0 0 |
$table-card-margin | 0 0 1rem 0 |
$table-color | black |
$table-current-sort-border-color | var(--#{$prefix}grey) |
$table-current-sort-font-weight | 700 |
$table-current-sort-hover-border-color | var(--#{$prefix}grey) |
$table-detail-background | #fafafa |
$table-detail-box-shadow | inset 0 1px 3px var(--#{$prefix}grey) |
$table-detail-chevron-color | var(--#{$prefix}primary) |
$table-detail-chevron-width | 40px |
$table-detail-padding | 1rem |
$table-focus-border-color | var(--#{$prefix}primary) |
$table-focus-box-shadow | 0 0 0 0.125em rgba(var(--#{$prefix}primary), 0.25) |
$table-hoverable-background-color | #fafafa |
$table-narrow-padding | 0.25em 0.5em |
$table-row-active-background-color | var(--#{$prefix}primary) |
$table-row-active-color | var(--#{$prefix}primary-invert) |
$table-sticky-header-height | 300px |
$table-sticky-zindex | 1 |
$table-striped-background-color | #fafafa |
$table-td-border | 1px solid var(--#{$prefix}grey-lighter) |
$table-td-padding | 0.5em 0.75em |
$table-th-border | 2px solid var(--#{$prefix}grey-lighter) |
$table-th-checkbox-width | 40px |
$table-th-color | #363636 |
$table-th-detail-width | 14px |
$table-th-font-weight | 600 |
$table-th-padding | 0.5em 0.75em |
$table-pagination-padding | 0.5em 0 |
See ➜ 📄 Full scss file
Current theme ➜ Bootstrap
SASS Variable | Default |
---|---|
$table-head-bg | initial |
$table-head-color | initial |
$table-head-border-width | var(--#{$prefix}border-width) |
$table-sticky-zindex | 1 |
$table-sticky-bg | initial |
$table-sticky-color | initial |
$table-sticky-header-height | 350px |
$table-detail-padding | 0.5em 0.75em |
$table-detail-bg | var(--#{$prefix}gray-light) |
$table-empty-padding | 1.5em 0 |
$table-sortable-hover-border-color | var(--#{$prefix}secondary) |
$table-current-sort-bg | var(--#{$prefix}gray-light) |
$table-card-spacer | $spacer |
See ➜ 📄 Full scss file