Skip to content

CommonTable

Supports elTableV1 and elTableV2.

Size

loading

Basic Usage

The following example uses config obtained via useConfigs, internally wrapped with reactive. Of course, you can also pass in an array directly. It is recommended to use useConfigs as it allows for continuous data operation expansion.

loading

Using Virtualization

Note that the external container needs to have a definite height and width when using virtualized tables.

loading

Supports All Native Table Component Usages

Native slots will be rendered first, followed by config configuration appending. Operation columns can use fixed positioning to the right.

loading

Enable Index

loading

Enable Selection

loading

Multi-level Headers

loading

Using Slots

html
<template #field1="{cellData,column,rowData,rowIndex,tableData}">
  cellData: current cell data, column: current configuration item, rowData: current row data,
  rowIndex: current row index, tableData: table data
</template>

Special handling can be done using slots. Use field as the slot name.

loading

Using Sorting

You can configure sortable in config for sorting. If you need to support sorting for all columns, you can use global registration to inject.

text
registerComponentDefaultPropsMap({
    CommonTable:{
        sortable: true,
    }
})
loading

Add Tips to Headers

loading

Custom Header Rendering

js
function renderHeaderScope({ $index, column, store, _self }, { configItem, index }) {
  //{ $index, column, store, _self } original parameters
  //$index index
  //column column configuration
  //store
  //_self
  //{ configItem, index } extended parameters
  //configItem column configuration item
  //index column index
}
loading

Cell formatter

js
function formatter(rowData) {
  //rowData row data
}
loading

Custom Cell Rendering

js
function cellRenderer({ cellData, column, rowData, rowIndex, tableData }) {
  //cellData cell data
  //column column configuration
  //rowData row data
  //rowIndex row index
  //tableData table data
}
loading

Hide Columns

js
// Can be Boolean | function type | reactive
// Function type usage
function hidden({ configItem, tableData }) {
  //configItem column configuration
  //tableData table data
}
loading

Component Switching

js
function component({ cellData, column, rowData, rowIndex, tableData }) {
  //cellData cell data
  //column column configuration
  //rowData row data
  //rowIndex row index
  //tableData table data
}
loading

Editable Fields

loading

Disable Cells

js
function isDisabled({ cellData, column, rowData, rowIndex, tableData }) {
  //cellData cell data
  //column column configuration
  //rowData row data
  //rowIndex row index
  //tableData table data

  return true | false;
}
loading

Field Validation

loading

Row Drag and Drop Sorting

loading

Table Props

ParameterTypeDefaultDescription
configCommonTableConfig[]-Table column configuration array, used to define properties and behaviors of each column.
v2booleanfalseWhether to enable v2 version style and functionality (compatible with old version).
dataDataType-Table data source, usually an array of objects.
loadingbooleanfalseWhether to show loading state.
emptystring-Text displayed when data is empty.
useIndexbooleanfalseWhether to show index column.
useSelectionbooleanfalseWhether to show selection column.
singleSelectionbooleanfalseEnable selection single selection.
useDragbooleanfalseEnable row dragging. Can be used with dragEnd event.

Element Plus Native Supported Props (elTable)

ParameterTypeDefaultDescription
rowKeystring | Function | symbol | number-Row data unique identifier field name or function.
heightnumber | string-Table height, if string must include unit (e.g. '300px').
widthnumber | string-Table width, if string must include unit.
maxHeightnumber | string-Table maximum height, if string must include unit.
stripebooleanfalseWhether to use zebra stripe table.
borderbooleanfalseWhether to show vertical borders.
size'large' | 'default' | 'small''default'Sets the size of table elements.
fitbooleantrueWhether column widths are adaptive.
showHeaderbooleantrueWhether to show table header.
highlightCurrentRowbooleanfalseWhether to highlight current row.
currentRowKeystring | number-Current row key, used to highlight specified row.
rowClassNamestring | Function-Row class name or function returning class.
rowStyleobject | Function-Row inline style object or function returning style.
cellClassNamestring | Function-Cell class name or function returning class.
cellStyleobject | Function-Cell inline style object or function returning style.
headerRowClassNamestring | Function-Header row class name or function returning class.
headerRowStyleobject | Function-Header row inline style object or function returning style.
headerCellClassNamestring | Function-Header cell class name or function returning class.
headerCellStyleobject | Function-Header cell inline style object or function returning style.
defaultExpandAllbooleanfalseWhether to expand all rows by default (valid for tree tables).
expandRowKeysArray<string | number>-Array of keys for initially expanded rows.
tooltipEffect'dark' | 'light''dark'Tooltip theme style.
tooltipOptionobject-Custom tooltip configuration items.
showSummarybooleanfalseWhether to show summary row at bottom.
sumTextstring'Total'Text for first column of summary row.
summaryMethodFunction-Custom summary calculation method.
spanMethodFunction-Method for merging rows or columns.
selectOnIndeterminatebooleanfalseControls whether to select on indeterminate state.
indentnumber16Pixel indentation for each level in tree structure.
lazybooleanfalseWhether to lazy load child node data.
loadFunction-Lazy loading callback function for loading child node data.
treePropsobject{ hasChildren: 'hasChildren', children: 'children' }Defines properties for tree structure.
tableLayoutstring'auto'Sets table layout method, such as 'fixed' or 'auto'.
scrollbarAlwaysOnbooleanfalseWhether to always show scrollbar.
showOverflowTooltipbooleanfalseWhether to show tooltip when cell content overflows.
flexiblebooleanfalseWhether to allow free column width adjustment.
defaultColMinWidthnumber80Minimum width for all columns.
columnany-Compatibility parameter, not recommended.

V2 Supported Props (elTableV2)

ParameterTypeDefaultDescription
cachenumber50Render cache row count, improves scrolling performance.
estimatedRowHeightnumber50Estimated row height, used for virtual scrolling calculation.
headerClassstring | Function-Header container class or dynamic generation function.
headerPropsobject | Function-Header container properties object or dynamic generation function.
headerCellPropsobject | Function-Header cell properties object or dynamic generation function.
headerHeightnumber | number[]50Header height, can pass array to set multi-row header height.
footerHeightnumber0Height of footer area.
rowClassstring | Function-Row container class or dynamic generation function.
rowPropsobject | Function-Row container properties object or dynamic generation function.
rowHeightnumber50Row height, used for virtual scrolling calculation.
cellPropsobject | Function-Cell properties object or dynamic generation function.
columnsColumn[]-Table column definition array.
dataGetterFunction-Function to get row data, used in virtual scrolling scenarios.
fixedDataRowDataType[]-Fixed row data, often used for fixed top or bottom rows.
expandedRowKeysArray<string | number>-Array of currently expanded row keys.
defaultExpandedRowKeysArray<string | number>-Array of initially expanded row keys.
classstring | string[] | object-Component root element class.
fixedbooleanfalseWhether to fix columns.
hScrollbarSizenumber-Size of horizontal scrollbar.
vScrollbarSizenumber-Size of vertical scrollbar.
sortByobject-Sort field and direction.
sortStateobject-Current sort state object.

Table Config

AttributeDescriptionTypeDefault
componentCustom cell rendering componentstring | ComponentType-
hiddenWhether to hide this columnboolean | Function | Ref | ComputedRef-
isDisabledWhether to disable this columnFunction-
labelFieldLabel field name[string]-
rulesForm validation rulesArrayable<FormItemRule> | Function-
helpTextHelp tooltip text[string]-
alignCell alignment'left' | 'center' | 'right'-
formatterCustom cell content formatting functionFunction-
columnChildrenChild column configuration for nested headersCommonTableConfig[]-
cellRendererCustom cell rendering functionFunction-
renderHeaderScopeCustom header title rendering functionFunction-

Element Plus Config Native Supported Attributes (el-table-column)

AttributeDescriptionTypeDefault
typeColumn type (selection/index/expand)[string]-
indexCustom index column starting value[number]-
columnKeyColumn unique identifier[string]-
widthColumn width[number]-
minWidthMinimum column widthstring | number-
fixedWhether column is fixedboolean-
renderHeaderCustom header rendering functionFunction-
sortableWhether sortableboolean-
sortMethodCustom sort methodFunction-
sortBySort fieldstring | string[] | Function-
sortOrdersSort order arraystring[]-
resizableWhether column width is adjustablebooleantrue
showOverflowTooltipShow tooltip on overflowboolean-
headerAlignHeader alignment'left' | 'center' | 'right'-
reserveSelectionReserve selected items in multiple selectionboolean-
filtersData filtering conditionsArray<{ text: string; value: string | number }>-
filterPlacementFilter popup position[string]-
filterMultipleWhether multiple filter selectionbooleantrue
filterMethodCustom filter methodFunction-
filteredValueCurrent column filter valuestring[]-

tableV2 Config

AttributeDescriptionType
componentSpecifies a Vue component for rendering cell content in this columnstring | ComponentType
hiddenControls whether current column is hidden, supports boolean or function dynamic controlboolean | Function | Ref | ComputedRef
isDisabledDetermines whether current column is disabled (often used for permission control)Function
labelFieldSets the label display field name for form fields[string]
rulesForm validation rules, supports array or function returning rulesArrayable<FormItemRule> | Function
helpTextHelp tooltip text displayed next to form items[string]
alignSets cell content alignment'left' | 'center' | 'right'
formatterCustom formatting function for modifying cell display contentFunction