Table

Display multiple data with similar format. You can sort, filter, compare your data in a table.

Basic table

Basic table is just for data display.

After setting attribute data of el-table with an object array, you can use prop (corresponding to a key of the object in data array) in el-table-column to insert data to table columns, and set the attribute label to define the column name. You can also use the attribute width to define the width of columns.

Striped Table

Striped table makes it easier to distinguish different rows.

Attribute stripe accepts a Boolean. If true, table will be striped.

Table with border

By default, Table has no vertical border. If you need it, you can set attribute border to true.

Table with status

You can highlight your table content to distinguish between "success, information, warning, danger" and other states.

Use row-class-name in el-table to add custom classes to a certain row. Then you can style it with custom classes.

Table with show overflow tooltip

When the content is too long, it will break into multiple lines, you can use show-overflow-tooltip to keep it in one line.

Attribute show-overflow-tooltip, which accepts a Boolean value. When set true, the extra content will show in tooltip when hover on the cell.

Table with fixed header

When there are too many rows, you can use a fixed header.

By setting the attribute height of el-table, you can fix the table header without any other codes.

Table with fixed column

When there are too many columns, you can fix some of them.

Attribute fixed is used in el-table-column, it accepts a Boolean. If true, the column will be fixed at left. It also accepts two string literals: 'left' and 'right', both indicating that the column will be fixed at corresponding direction.

Table with fixed columns and header

When you have huge chunks of data to put in a table, you can fix the header and columns at the same time.

Fix columns and header at the same time by combining the above two examples.

Fluid-height Table with fixed header (and columns)

When the the data is dynamically changed, you might want the table to have a maximum height rather than a fixed height and to show the scroll bar if needed.

By setting the attribute max-height of el-table, you can fix the table header. The table body scrolls only if the height of the rows exceeds the max height value.

Grouping table head

When the data structure is complex, you can use group header to show the data hierarchy.

Only need to place el-table-column inside a el-table-column, you can achieve group header.

Table with fixed group header

fixed group head is supported

The attribute fixed of the group header is determined by the outermost el-table-column

Single select

Single row selection is supported.

Table supports single row selection. You can activate it by adding the highlight-current-row attribute. An event called current-change will be triggered when row selection changes, and its parameters are the rows after and before this change: currentRow and oldCurrentRow. If you need to display row index, you can add a new el-table-column with its type attribute assigned to index, and you will see the index starting from 1.

Multiple select

You can also select multiple rows.

After 2.8.3, toggleRowSelection supports the third parameter ignoreSelectable to determine whether to ignore the selectable attribute.

Activating multiple selection is easy: simply add an el-table-column with its type set to selection.

Sorting

Sort the data to find or compare data quickly.

Set attribute sortable in a certain column to sort the data based on this column. It accepts Boolean with a default value false. Set table attribute default-sort to determine default sort column and order. To apply your own sorting rules, use sort-method or sort-by. If you need remote sorting from backend, set sortable to custom, and listen to the sort-change event on Table. In the event handler, you have access to the sorting column and sorting order so that you can fetch sorted table data from API. In this example we use another attribute named formatter to format the value of certain columns. It accepts a function which has two parameters: row and column. You can handle it according to your own needs.

Filter

Filter the table to find desired data.

Set attribute filters and filter-method in el-table-column makes this column filterable. filters is an array, and filter-method is a function deciding which rows are displayed. It has three parameters: value, row and column.

Custom column template

Customize table column so it can be integrated with other components.

You have access to the following data: row, column, $index and store (state management of Table) by slot.

Table with custom header

Customize table header so it can be even more customized.

You can customize how the header looks by header slots.

Expandable row

When the row content is too long and you do not want to display the horizontal scroll bar, you can use the expandable row feature.

Activate expandable row by adding type="expand" and slot. The template for el-table-column will be rendered as the contents of the expanded row, and you can access the same attributes as when you are using slot in custom column templates.

switch parent border:
switch child border:

Tree data and lazy mode

You can display tree structure data. When row contains the children field, it is treated as nested data. For rendering nested data, the prop row-key is required. Also, child row data can be loaded asynchronously. Set lazy property of Table to true and the function load. Specify hasChildren attribute in row to determine which row contains children. Both children and hasChildren can be configured via tree-props.

Selectable tree 2.8.0

When treeProps.checkStrictly is true, the selection state of parent and child nodes is no longer associated, that is, when the parent node is selected, its child nodes will not be selected; when treeProps.checkStrictly is false, the selection state of parent and child nodes will be associated with the selection state of child nodes, that is, when the parent node is selected, all its child nodes will be selected.

Summary row

For table of numbers, you can add an extra row at the table footer displaying each column's sum.

You can add the summary row by setting show-summary to true. By default, for the summary row, the first column does not sum anything up but always displays 'Sum' (you can configure the displayed text using sum-text), while other columns sum every number in that column up and display them. You can of course define your own sum behaviour. To do so, pass a method to summary-method, which returns an array, and each element of the returned array will be displayed in the columns of the summary row, It can be a VNode or string. The second table of this example is a detailed demo.

Rowspan and colspan

Configuring rowspan and colspan allows you to merge cells

Use the span-method attribute to configure rowspan and colspan. It accepts a method, and passes an object to that method including current row row, current column column, current row index rowIndex and current column index columnIndex. The method should return an array of two numbers, the first number being rowspan and second colspan. It can also return an object with rowspan and colspan props.

Custom index

You can customize row index in type=index columns.

To customize row indices, use index attribute on el-table-column with type=index. If it is assigned to a number, all indices will have an offset of that number. It also accepts a method with each index (starting from 0) as parameter, and the returned value will be displayed as index.

Table Layout

The table-layout property sets the algorithm used to lay out table cells, rows, and columns.

Table API

Table Attributes

NameDescriptionTypeDefault
datatable dataarray[]
heighttable's height. By default it has an auto height. If its value is a number, the height is measured in pixels; if its value is a string, the value will be assigned to element's style.height, the height is affected by external stylesstring / number
max-heighttable's max-height. The legal value is a number or the height in pxstring / number
stripewhether Table is stripedbooleanfalse
borderwhether Table has vertical borderbooleanfalse
sizesize of Tableenum
fitwhether width of column automatically fits its containerbooleantrue
show-headerwhether Table header is visiblebooleantrue
highlight-current-rowwhether current row is highlightedbooleanfalse
current-row-keykey of current row, a set only propstring / number
row-class-namefunction that returns custom class names for a row, or a string assigning class names for every rowFunction / string
row-stylefunction that returns custom style for a row, or an object assigning custom style for every rowFunction / object
cell-class-namefunction that returns custom class names for a cell, or a string assigning class names for every cellFunction / string
cell-stylefunction that returns custom style for a cell, or an object assigning custom style for every cellFunction / object
header-row-class-namefunction that returns custom class names for a row in table header, or a string assigning class names for every row in table headerFunction / string
header-row-stylefunction that returns custom style for a row in table header, or an object assigning custom style for every row in table headerFunction / object
header-cell-class-namefunction that returns custom class names for a cell in table header, or a string assigning class names for every cell in table headerFunction / string
header-cell-stylefunction that returns custom style for a cell in table header, or an object assigning custom style for every cell in table headerFunction / object
row-keykey of row data, used for optimizing rendering. Required if reserve-selection is on or display tree data. When its type is String, multi-level access is supported, e.g. user.info.id, but user.info[0].id is not supported, in which case Function should be usedfunction / string
empty-textdisplayed text when data is empty. You can customize this area with #emptystringNo Data
default-expand-allwhether expand all rows by default, works when the table has a column type="expand" or contains tree structure databooleanfalse
expand-row-keysset expanded rows by this prop, prop's value is the keys of expand rows, you should set row-key before using this proparray
default-sortset the default sort column and order. property prop is used to set default sort column, property order is used to set default sort orderobjectif prop is set, and order is not set, then order is default to ascending
tooltip-effectthe effect of the overflow tooltipenumdark
tooltip-options 2.2.28the options for the overflow tooltip, see the following tooltip componentobjectobject
append-filter-panel-to 2.8.4which element the filter panels appends tostring
show-summarywhether to display a summary rowbooleanfalse
sum-textdisplayed text for the first column of summary rowstringSum
summary-methodcustom summary methodFunction
span-methodmethod that returns rowspan and colspanFunction
select-on-indeterminatecontrols the behavior of master checkbox in multi-select tables when only some rows are selected (but not all). If true, all rows will be selected, else deselectedbooleantrue
indenthorizontal indentation of tree datanumber16
lazywhether to lazy loading databooleanfalse
loadmethod for loading child row data, only works when lazy is trueFunction
tree-propsconfiguration for rendering nested dataobjectobject
table-layoutsets the algorithm used to lay out table cells, rows, and columnsenumfixed
scrollbar-always-onalways show scrollbarbooleanfalse
show-overflow-tooltipwhether to hide extra content and show them in a tooltip when hovering on the cell.It will affect all the table columns, refer to table tooltip-optionsboolean / object 2.3.7
flexible 2.2.1ensure main axis minimum-size doesn't follow the contentbooleanfalse
scrollbar-tabindex 2.8.3body scrollbar's wrap container tabindexstring / number

Table Events

NameDescriptionType
selecttriggers when user clicks the checkbox in a rowFunction
select-alltriggers when user clicks the checkbox in table headerFunction
selection-changetriggers when selection changesFunction
cell-mouse-entertriggers when hovering into a cellFunction
cell-mouse-leavetriggers when hovering out of a cellFunction
cell-clicktriggers when clicking a cellFunction
cell-dblclicktriggers when double clicking a cellFunction
cell-contextmenutriggers when user right clicks on a cellFunction
row-clicktriggers when clicking a rowFunction
row-contextmenutriggers when user right clicks on a rowFunction
row-dblclicktriggers when double clicking a rowFunction
header-clicktriggers when clicking a column headerFunction
header-contextmenutriggers when user right clicks on a column headerFunction
sort-changetriggers when Table's sorting changesFunction
filter-changecolumn's key. If you need to use the filter-change event, this attribute is mandatory to identify which column is being filteredFunction
current-changetriggers when current row changesFunction
header-dragendtriggers after changing a column's width by dragging the column header's borderFunction
expand-changetriggers when user expands or collapses a row (for expandable table, second param is expandedRows; for tree Table, second param is expanded)Function
scroll 2.9.0Invoked after scrolledFunction

Table Slots

NameDescriptionSubtags
defaultcustomize default contentTable-column
appendContents to be inserted after the last row. You may need this slot if you want to implement infinite scroll for the table. This slot will be displayed above the summary row if there is one.
emptyyou can customize content when data is empty.

Table Exposes

MethodDescriptionType
clearSelectionused in multiple selection Table, clear user selectionFunction
getSelectionRowsreturns the currently selected rowsFunction
toggleRowSelectionused in multiple selection Table, toggle if a certain row is selected. With the second parameter, you can directly set if this row is selectedFunction
toggleAllSelectionused in multiple selection Table, toggle select all and deselect allFunction
toggleRowExpansionused in expandable Table or tree Table, toggle if a certain row is expanded. With the second parameter, you can directly set if this row is expanded or collapsedFunction
setCurrentRowused in single selection Table, set a certain row selected. If called without any parameter, it will clear selectionFunction
clearSortclear sorting, restore data to the original orderFunction
clearFilterclear filters of the columns whose columnKey are passed in. If no params, clear all filtersFunction
doLayoutrefresh the layout of Table. When the visibility of Table changes, you may need to call this method to get a correct layoutFunction
sortsort Table manually. Property prop is used to set sort column, property order is used to set sort orderFunction
scrollToscrolls to a particular set of coordinatesFunction
setScrollTopset vertical scroll positionFunction
setScrollLeftset horizontal scroll positionFunction
columns 2.7.6Get table columns context.array
updateKeyChildren 2.8.4used in lazy Table, must set rowKey, update key childrenFunction

Table-column API

Table-column Attributes

NameDescriptionTypeDefault
typetype of the column. If set to selection, the column will display checkbox. If set to index, the column will display index of the row (staring from 1). If set to expand, the column will display expand iconenumdefault
indexcustomize indices for each row, works on columns with type=indexnumber / Function
labelcolumn labelstring
column-keycolumn's key. If you need to use the filter-change event, you need this attribute to identify which column is being filteredstring
propfield name. You can also use its alias: propertystring
widthcolumn widthstring / number''
min-widthcolumn minimum width. Columns with width has a fixed width, while columns with min-width has a width that is distributed in proportionstring / number''
fixedwhether column is fixed at left / right. Will be fixed at left if trueenum / booleanfalse
render-headerrender function for table header of this columnFunction
sortablewhether column can be sorted. Remote sorting can be done by setting this attribute to 'custom' and listening to the sort-change event of Tableboolean / stringfalse
sort-methodsorting method, works when sortable is true. Should return a number, just like Array.sortFunction
sort-byspecify which property to sort by, works when sortable is true and sort-method is undefined. If set to an Array, the column will sequentially sort by the next property if the previous one is equalFunction / string / object
sort-ordersthe order of the sorting strategies used when sorting the data, works when sortable is true. Accepts an array, as the user clicks on the header, the column is sorted in order of the elements in the arrayobject['ascending', 'descending', null]
resizablewhether column width can be resized, works when border of el-table is truebooleantrue
formatterfunction that formats cell contentfunction
show-overflow-tooltipwhether to hide extra content and show them in a tooltip when hovering on the cellboolean / object 2.2.28undefined
alignalignmentenumleft
header-alignalignment of the table header. If omitted, the value of the above align attribute will be appliedenumleft
class-nameclass name of cells in the columnstring
label-class-nameclass name of the label of this columnstring
selectablefunction that determines if a certain row can be selected, works when type is 'selection'Function
reserve-selectionwhether to reserve selection after data refreshing, works when type is 'selection'. Note that row-key is required for this to workbooleanfalse
filtersan array of data filtering options. For each element in this array, text and value are requiredarray
filter-placementplacement for the filter dropdownenum
filter-class-name 2.5.0className for the filter dropdownstring
filter-multiplewhether data filtering supports multiple optionsbooleantrue
filter-methoddata filtering method. If filter-multiple is on, this method will be called multiple times for each row, and a row will display if one of the calls returns truefunction
filtered-valuefilter value for selected data, might be useful when table header is rendered with render-headerobject

Table-column Slots

NameDescriptionType
defaultCustom content for table columnsobject
headerCustom content for table headerobject
filter-icon 2.7.8Custom content for filter iconobject

Type Declarations

Show declarations
ts
interface Sort {
  prop: string
  order: 'ascending' | 'descending'
  init?: any
  silent?: any
}

interface TreeNode {
  expanded?: boolean
  loading?: boolean
  noLazyChildren?: boolean
  indent?: number
  level?: number
  display?: boolean
}

FAQ

How to use image preview in the table?

vue
<template>
  <el-table-column width="180">
    <template #default="scope">
      <el-image preview-teleported :preview-src-list="srcList" />
    </template>
  </el-table-column>
</template>

Why column is not rendered when use DOM templates?

Typical issue: #5046 #5862 #6919

This is because the HTML spec only allows a few specific elements to omit closing tags, the most common being <input> and <img>. For all other elements, if you omit the closing tag, the native HTML parser will think you never terminated the opening tag

For more details please refer to vue docs

Source

ComponentStyleDocs

Contributors