Tables are used to present structured data content, usually accompanied by the ability to manipulate the data (sort, search, paginate...).
API doc
Design doc
How to Use
Into the header. columns And data. DataSource To render.
Please provide a "key" for each data item in the dataSource that is different from the value of the other data items, or use the row Key parameter to specify an attribute name as the primary key, alternative row operation functions such as row selection and expansion of the table.
For tables, the two most basic parameters are dataSource and columns, the former is the data item, the latter is the configuration of each column, both are array types.
You can also use JSX syntax definitions columns, note that Table only supports columns JSX syntax definition. You cannot use any component package Table.Column.
Note: JSX-written tables are not supported the parameter Resizable.
Notice
When columns are written in JSX, please do not use it at the same time as the configuration method; if used at the same time, only the configuration method will take effect, and no aggregation operation will be performed.
This feature can be turned on by passing in rowSelection.
Click the selection box in the header, and all rows in the dataSource that are not in the state of disabled will be selected. The callback function for selecting all rows is onSelectAll;
Clicking on the row selection box will select the current row. Its callback function is onSelect;
注意事项
1. Be sure to provide a "key" for each row of data that is different from other row values, or use the rowKey parameter to specify a property name as the primary key.
2. If you encounter the problem of returning to the first page after clicking a row selection on the second page, please check whether component rendering triggers "dataSource" update (shallow equal). After the "dataSource" is updated, the uncontrolled page turner will return to the first page. Please put "dataSource" inside state.
Table paging currently supports two modes: controlled and uncontrolled.
In controlled mode, the paging state is passed entirely externally, depending on whether the pagination .currentPage field is passed. In general, the controlled mode is suitable for remotely pulling data and rendering.
In uncontrolled mode, Table passes the incoming dataSource length as total to the Pagination component by default, and of course you can also pass a total field to overwrite the value of the Table component, but we do not recommend users to pass this field in uncontrolled paging mode.
Note: The custom pagination.total field passed in uncontrolled conditions is supported only after version 0.25.0.
Under normal circumstances, the data is often not obtained at one time. We will retrieve the data from the interface when clicking on the page number, filter or sort button. In this case, please use Controlled mode To handle pagination. The user needs to pass in the pagination.currentPage field, where the rendering of the pagination component depends entirely on the incoming pagination object.
Notice
1. When pagination is an object type, literal is not recommended because it causes the table to render to its original state (it looks like the pager is not working). Please try to define reference type parameters outside the render method. If hooks are used, please use useMemo or useState for storage.
2. In the controlled mode, Table will not paginate dataSource, please pass in current page data to dataSource
You can fix the column by setting the Fixed attribute of the column and scroll.x, and fix the header by setting scroll.y.
It is recommended to specify scroll.x as a fixed value or percentage greater than the width of the table. If it is a fixed value, set it to >= the sum of all fixed column widths + the sum of all table column widths.
Make sure that all elements inside the table do not affect the height of the cells after rendering (e.g. containing unloaded pictures, etc.). In this case, give the stator element a definite height to ensure that the left and right Fixed columns of cells are not deranged.
If the column header is not aligned with the content or there is a column duplication or when the fixed column fails, specify the width width of the fixed column, if still not effective, try to recommend leaving a column with no width to accommodate the elastic layout, or check for ultra-long continuous fields to destroy the layout.
The header can be fixed to the top of the page with the sticky property. v2.21 version support. When passing top, you can control the distance from the scroll container.
After turning on sticky, Table will automatically turn on the fixed layout, and the column width will be determined by column.width. Columns without a given width are automatically assigned by the browser.
Filters and sorting controls are integrated inside the table, and users can pass in the sorter display of the sorter open header by passing filters in Column and the filter control display of the onFilter open header.
Note: Be sure to provide a "key" for each row of data that is different from other row values, or use the rowKey parameter to specify a property name as the primary key.
Note: Sorting and filtering columns must set independent "dataIndex"
When sorter is a function type, the sortOrder status can be obtained through the third parameter of the function. The function type is (a?: RecordType, b?: RecordType, sortOrder?: 'ascend' | 'descend') => number. Supported by version v2.47.
You can control whether to display the sorting tip through the showSortTip attribute. It is supported since v2.65 and defaults to false. When the tip is turned on, when there is only sorting function, the sorting prompt will be displayed when the mouse is moved to the table header; in other cases, the sorting prompt will be displayed only when the mouse is moved to the sorting icon.
Note: When using the sortOrder attribute for controlled sorting, since the next sort order cannot be predicted, showSortTip does not take effect and the prompt will not be displayed.
Use renderFilterDropdown to customize the render filter panel. v2.52 supported.
You can call setTempFilteredValue to store the filter value when the user enters the filter value, and call confirm to trigger the actual filtering after the filter value is entered. You can also filter directly through confirm({ filteredValue }).
The reason for setting tempFilteredValue is that in scenarios where temporary filtered values need to be stored, there is no need to declare a state to save this temporary filtered value.
type RenderFilterDropdown = (props?: RenderFilterDropdownProps) => React.ReactNode;
interface RenderFilterDropdownProps {
/** Temporary filter value, the initial value is `filteredValue` or `defaultFilteredValue` */
tempFilteredValue: any[];
/** Set temporary filter value */
setTempFilteredValue: (tempFilteredValue: any[]) => void;
/** `confirm` will assign `tempFilteredValue` to `filteredValue` by default and trigger the `onChange` event. You can also set the filter value directly by passing in `filteredValue` */
confirm: (props?: { closeDropdown?: boolean; filteredValue?: any[] }) => void;
/** Clear filter values and temporary filter values */
clear: (props?: { closeDropdown?: boolean }) => void;
/** Close dropdown */
close: () => void;
/** Filter configuration items, do not pass if not required */
filters?: RenderDropdownProps['filters']
}
1. Since version `0.27.0`, the unfold button will be rendered in the same cell as the first column, and you can open a separate column of rendering by passing in `hideExpandedColumn = `.
2. Be sure to provide a "key" for each row of data that is different from the other row values, or use the rowKey parameter to specify an attribute name as the primary key.
A Common Table That Can Be Expanded
If you need to render a table that can be expanded, in addition to the need to pass expandedRowRender In addition to this method, you must specify rowKey(by default key), Table will be based on rowKey Gets a row unique identifier.
If rowKey is a Function, the result of rowKey(record) is taken as the row unique ID
If rowKey is a string type, you take record[rowKey] as the row unique ID
The Unfold Button Is Rendered In a Separated Column
Version: >= 0.27.0
By default, the expansion button will be rendered in the same cell as the first copy, and you can enter hideExpandedColumn={false} to render as a separate column:
You can pass the row Expandable method, enter the reference as record, and determine whether the return value is false to close the rendering of the expandable button on a row.
The table supports the display of tree data and is automatically displayed as a tree table when there are children fields in the data. If you do not need or use other fields, you can configure it with the childrenRecordName. In addition, you can control the indent width of each layer by setting indent Size.
Note: Be sure to provide a "key" for each row of data that is different from the other row values, or use the rowKey parameter to specify a property name as the primary key.
Use ellipsis to make cells automatically clipped. v2.34.0 support.
import React from 'react';
import { Table } from '@douyinfe/semi-ui';
import { IconMore } from '@douyinfe/semi-icons';
function App() {
const columns = [
{
title: 'Title',
dataIndex: 'name',
fixed: true,
width: 250,
filters: [
{
text: 'Semi Design',
value: 'Semi Design',
},
{
text: 'Semi D2C',
value: 'Semi D2C',
},
],
onFilter: (value, record) => record.name.includes(value),
sorter: (a, b) => (a.name.length - b.name.length > 0 ? 1 : -1),
ellipsis: true,
},
{
title: 'Owner',
dataIndex: 'owner',
width: 200,
ellipsis: true,
filters: [
{
text: 'Semi Design',
value: 'Semi Design',
},
{
text: 'Semi D2C',
value: 'Semi D2C',
},
],
onFilter: (value, record) => record.name.includes(value),
sorter: (a, b) => (a.name.length - b.name.length > 0 ? 1 : -1),
},
{
title: 'Size',
dataIndex: 'size',
sorter: (a, b) => (a.name.length - b.name.length > 0 ? 1 : -1),
ellipsis: true,
},
{
title: 'Update time',
dataIndex: 'updateTime',
width: 200,
ellipsis: true,
},
{
title: '',
dataIndex: 'operate',
fixed: 'right',
align: 'center',
width: 100,
render: () => {
return <IconMore />;
},
},
];
const data = [
{
key: '1',
name: 'Maintained by the Douyin front-end and UED teams, an easy-to-customize modern design system that helps designers and developers create high-quality products.',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
size: '2M',
owner: 'Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang',
updateTime: '2020-02-02 05:13',
avatarBg: 'grey',
},
{
key: '2',
name: 'Semi is designed based on FA architecture, and the main logic is extracted as Foundation package, which is easy to migrate to other frameworks',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
size: '2M',
owner: 'Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao',
updateTime: '2020-02-02 05:13',
avatarBg: 'red',
},
{
key: '3',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
name: 'Maintained by the Douyin front-end and UED teams, an easy-to-customize modern design system that helps designers and developers create high-quality products.',
size: '34KB',
owner: 'Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang',
updateTime: '2020-02-02 05:13',
avatarBg: 'light-blue',
},
{
key: '4',
name: 'Semi is designed based on FA architecture, and the main logic is extracted as Foundation package, which is easy to migrate to other frameworks',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
size: '34KB',
owner: 'Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao',
updateTime: '2020-02-02 05:13',
avatarBg: 'light-blue',
},
];
return <Table scroll={{ x: 1200 }} columns={columns} dataSource={data} pagination={false} />;
}
render(App);
Set ellipsis.showTitle to false to hide the default native HTML title. With column.render you can customize the content prompt.
import React from 'react';
import { Table, Typography } from '@douyinfe/semi-ui';
import { IconMore } from '@douyinfe/semi-icons';
function App() {
const columns = [
{
title: 'Title',
dataIndex: 'name',
fixed: true,
width: 250,
filters: [
{
text: 'Semi Design',
value: 'Semi Design',
},
{
text: 'Semi D2C',
value: 'Semi D2C',
},
],
onFilter: (value, record) => record.name.includes(value),
sorter: (a, b) => (a.name.length - b.name.length > 0 ? 1 : -1),
ellipsis: { showTitle: false },
render: (text) => <Typography.Text ellipsis={{ showTooltip: true }}>{text}</Typography.Text>,
},
{
title: 'Owner',
dataIndex: 'owner',
width: 200,
filters: [
{
text: 'Semi Design',
value: 'Semi Design',
},
{
text: 'Semi D2C',
value: 'Semi D2C',
},
],
onFilter: (value, record) => record.name.includes(value),
sorter: (a, b) => (a.name.length - b.name.length > 0 ? 1 : -1),
ellipsis: { showTitle: false },
render: (text) => <Typography.Text ellipsis={{ showTooltip: true }}>{text}</Typography.Text>,
},
{
title: 'Size',
dataIndex: 'size',
sorter: (a, b) => (a.name.length - b.name.length > 0 ? 1 : -1),
ellipsis: true,
},
{
title: 'Update time',
dataIndex: 'updateTime',
width: 200,
ellipsis: true,
},
{
title: '',
dataIndex: 'operate',
fixed: 'right',
align: 'center',
width: 100,
render: () => {
return <IconMore />;
},
},
];
const data = [
{
key: '1',
name: 'Maintained by the Douyin front-end and UED teams, an easy-to-customize modern design system that helps designers and developers create high-quality products.',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/figma-icon.png',
size: '2M',
owner: 'Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang',
updateTime: '2020-02-02 05:13',
avatarBg: 'grey',
},
{
key: '2',
name: 'Semi is designed based on FA architecture, and the main logic is extracted as Foundation package, which is easy to migrate to other frameworks',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
size: '2M',
owner: 'Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao',
updateTime: '2020-02-02 05:13',
avatarBg: 'red',
},
{
key: '3',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
name: 'Maintained by the Douyin front-end and UED teams, an easy-to-customize modern design system that helps designers and developers create high-quality products.',
size: '34KB',
owner: 'Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang Pengzhi Jiang',
updateTime: '2020-02-02 05:13',
avatarBg: 'light-blue',
},
{
key: '4',
name: 'Semi is designed based on FA architecture, and the main logic is extracted as Foundation package, which is easy to migrate to other frameworks',
nameIconSrc: 'https://lf3-static.bytednsdoc.com/obj/eden-cn/ptlz_zlp/ljhwZthlaukjlkulzlp/docs-icon.png',
size: '34KB',
owner: 'Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao Xuan Hao',
updateTime: '2020-02-02 05:13',
avatarBg: 'light-blue',
},
];
return <Table scroll={{ x: 1200 }} columns={columns} dataSource={data} pagination={false} />;
}
render(App);
Resizable Column
Version > = 0.15.0
Basic Resizable Column
For some columns with more content, you can choose to turn on the telescopic column function and pull and pull at the head to realize the real-time change of column width.
But you need to pay attention to some parameters:
resizable is set to true or an object
Any column in columns that requires a telescopic function should specify the widthfield (if not passed, the column does not have a telescopic function and its column width will be automatically adjusted by the browser)
column.resize can take effect after resizable is enabled. After setting to false, the column no longer supports scaling. v2.42 support
When used with fixed columns, you need to specify a column without setting the width
It is not recommended to use it with scroll.x at the same time. scroll.x specifies that the table has a width range, and stretching columns will expand the column width, which may cause the table to be misaligned
resizable can also be an object, including three event methods:
onResize
onResizeStart
onResizeStop
These three callback will be triggered on changing column width, start changing column width and stop changing column width respectively. Developers can choose to modify the column at this time, such as adding a vertical line effect when dragging, as shown below.
For some tables whose data needs to be displayed in groups, you can pass in groupBy to define the grouping rules, and use renderGroupSection to define the rendering of the grouping table header.
Note: Be sure to provide a "key" for each row of data that is different from other row values, or use the rowKey parameter to specify a property name as the primary key.
Virtualization can be used for scenes that need to render large-scale data. You can enable this feature by configuring the virtualized parameter. have to be aware of is:
Must pass scroll.y (number) andstyle.width (number);
Need to pass the height of each line virtualized.itemSize (when not transmitting, the normal line height defaults to 56, and the group head line height defaults to 56), can be of the following types:
number
(index, { sectionRow?: boolean, expandedRow?: boolean }) => number
Table grouping virtualization requires version >= 0.37.0.
The following is an example of rendering 1000 pieces of data.
Generally, you can use Column.render, but you can also passColumn.useFullRender = true to enable full custom rendering mode. At this time, the components such as checkbox button, expand button, indent will be Pass through to the Column.title andColumn.render methods, you can further define the rendering method of the header and cell content.
The input parameters accepted by Column.title are:
Users can use the header merge function to group the header. The header merge can be combined with fixed column, virtualization, data grouping, column scaling and other functions. It also supports JSX or configurable writing.
The third parameter DOMEvent requires version >=0.28.0
onExpandedRowsChange
Triggers when unfolding row changes
(rows: RecordType[]) => void
onGroupedRow
Similar to onRow, but this parameter is used to define the row attribute of the grouping header alone
(record: RecordType, index: number) => object
0.29.0
onHeaderRow
Set the header row property, and the returned object is merged to the header line
(columns: Column[], index: number) => object
onRow
Set the row property, and the returned object is merged to the table row
(record: RecordType, index: number) => object
Some of the type definitions used above:
// PaginationProps is the props supported by the Pagination component
interface TablePaginationProps extends PaginationProps {
position?: PaginationPosition;
formatPageText?: FormatPageText;
}
type VirtualizedItemSizeFn = (index?: number) => number;
type VirtualizedOnScrollArgs = {
scrollDirection?: 'forward' | 'backward';
scrollOffset?: number;
scrollUpdateWasRequested?: boolean;
};
type VirtualizedOnScroll = (object: VirtualizedOnScrollArgs) => void;
type Virtualized =
| boolean
| {
itemSize?: number | VirtualizedItemSizeFn;
onScroll?: VirtualizedOnScroll;
};
RecordType is a generic parameter of Table and Column, and the default is object type. You can use RecordType like this:
import { ColumnProps } from 'table/interface';
interface Record {
title?: string;
dataIndex?: string;
width?: number;
render?: Function;
key?: string;
name?: string;
age?: number;
address?: string;
}
const columns: ColumnProps<Record>[] = [
{
title: 'Name',
dataIndex: 'name',
width: 200,
},
// ...
];
const data: Record[] = [
{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
},
// ...
];
function App() {
return <Table<Record> columns={columns} dataSource={data} />;
}
onRow/onHeaderRow Usage
Also in column.onCellcolumn.onHeaderCell Properties or events supported by td / th can also be returned.
import React from 'react';
import { Table } from '@douyinfe/semi-ui';
() => (
<Table
onRow={(record, index) => {
return {
onClick: event => {},
onMouseEnter: event => {},
onMouseLeave: event => {},
className: '',
// ...
// Other attributes or events that can be applied to tr
};
}}
onHeaderRow={(columns, index) => {
return {
onClick: event => {},
onMouseEnter: event => {},
onMouseLeave: event => {},
className: '',
// ...
// Other attributes or events that can be applied to th
};
}}
/>
);
Column
Parameters
Instructions
Type
Default
Version
align
Setting the alignment of columns
'left '| 'right '| 'center'
'left'
children
Settings for sub-columns when the header is merged
Column[]
className
Column style name
string
colSpan
When header columns merge, set to 0, do not render
number
dataIndex
The key corresponding to the column data in the data item. It is required when using sorter or filter.
string
defaultFilteredValue
Default value of the filter, the filter state of the external control column with a value of the screened value array
any[]
2.5.0
defaultSortOrder
The default value of sortOrder, one of 'ascend'|'descend'|false
boolean| string
false
1.31.0
direction
RTL, LTR direction, the default value is equal to ConfigProvider direction, you can configure the direction of the Table separately here
'ltr' | 'rtl'
2.31.0
ellipsis
Ellipsis Text, table-layout will automatically switch to fixed after it is turned on
boolean| { showTitle: boolean }
false
2.34.0
filterChildrenRecord
Whether the child data needs to be filtered locally. If this function is enabled, if the child meets the filtering criteria, the parent will retain it even if it does not meet the criteria.
boolean
0.29.0
filterDropdown
You can customize the filter menu. This function is only responsible for rendering the layer and needs to write a variety of interactions.
ReactNode
filterDropdownProps
Props passing to Dropdown, see more in Dropdown API
Controlled property of the filter, the filter state of the external control column with a value of the screened value array
any[]
filters
Filter menu items for the header
Filter[]
fixed
Whether the column is fixed, optional true (equivalent to left) 'left' 'right'
boolean|string
false
key
The key required by React, if a unique dataIndex has been set, can ignore this property
string
render
A rendering function that generates complex data, the parameters are the value of the current row, the current row data, the row index, and the table row / column merge can be set in return object
Whether to enable resize mode, this property will take effect only after Table resizable is enabled
boolean
2.42.0
showSortTip
Whether to display sorting tips, If sortOrder is set and sorting is controlled, this parameter will not take effect
boolean
false
2.65.0
sortChildrenRecord
Whether to sort child data locally
boolean
0.29.0
sortOrder
The controlled property of the sorting, the sorting of this control column can be set to 'ascend'|'descended '|false
boolean
false
sorter
Sorting function, local sorting uses a function (refer to the compareFunction of Array.sort), requiring a server-side sorting can be set to true. An independent dataIndex must be set for the sort column, and an independent key must be set for each data item in the dataSource
boolean|(r1: RecordType, r2: RecordType, sortOrder: 'ascend' | 'descend') => number
true
sortIcon
Customize the sort icon. The returned node controls the entire sort button, including ascending and descending buttons. Need to control highlighting behavior based on sortOrder
(props: { sortOrder }) => ReactNode
2.50.0
title
Column header displays text. When a function is passed in, title will use the return value of the function; when other types are passed in, they will be aggregated with sorter and filter. It needs to be used with useFullRender to obtain parameters such as filter in the function type
Whether to completely customize the rendering, see Full Custom Rendering for usage details, enabling this feature will cause a certain performance loss
boolean
false
0.34.0
width
Column width
string | number
onCell
Set cell properties
(record: RecordType, rowIndex: number) => object
onFilter
Determine the running function of the filter in local mode. An independent dataIndex must be set for the filter column, and an independent key must be set for each data item in the dataSource
// RecordType is a generic parameter of Table and Column, the default is object type
type Filter = {
value: any;
text: React.ReactNode;
children?: Filter[];
};
rowSelection
Parameters
Instructions
Type
Default
Version
className
Style name listed
string
disabled
Disabled Checkbox in Table header or not.
boolean
false
0.32.0
fixed
Secure the selection box column to the left.
boolean
false
getCheckboxProps
Default property configuration for the selection box
(record: RecordType) => object
hidden
Hide selection column or not
boolean
false
0.34.0
selectedRowKeys
Specifies the key array of the selected item, which needs to work with onChange
A callback in the event of a change in the selected item. The first parameter will save the row keys selected last time, even if you do paging control or update the dataSource FAQ
Whether to automatically scroll to the top of the table after paging, sorting, and filtering changes
boolean
false
1.1.0
x
Set the width of the horizontal scroll area, which can be pixel value, percentage, or 'max-content'
string|number
y
Set the height of the vertical scroll area, which can be a pixel value
number
pagination
Page-turning component configuration. Pagination suggests not to use literal value.
Note: After pagination.onChange is set, Table onChange no longer responds to pagination changes.
Parameters
Instructions
Type
Default
Version
currentPage
Current page number
number
-
defaultCurrentPage
Default current page number
number
1
>=1.1.0
formatPageText
Page-turning area copywriting custom formatting, pass false to close copywriting display; This item affects the copy display on the left of the page turning area of the form. It is different from the showTotal parameter of thePagination component.
The parameters of the resizable object type, which mainly include event methods when the table column is scaled. These event methods can return an object that merges with the final column.
Returns the data object of the current page: { dataSource: RecordType[], groups: Map<{groupKey: string, recordKeys: Set<string>}> }
0.37.0
Accessibility
ARIA
The role of the table is grid, and the role of the tree table is treegrid
the row's role is row, and the cell's role is gridcell
Added aria-rowcount and aria-colcount attributes to the table to indicate the number of rows and columns
The row has added aria-rowindex to indicate which row it currently belongs to, and the first row is 1
The row of the tree table has aria-level representing the tree level of the current row, the first level is 1
Expandable table rows have the aria-expanded attribute, indicating whether the current row is expanded
The new aria-colindex of the cell indicates which column the current grid belongs to, and the first column is 1
Added aria-label to column filter and sort buttons, and added aria-label attribute to row select buttons
RTL/LTR
RTL default value of Table is controlled by ConfigProvider
The align and fixed properties of the Table column will be automatically switched in RTL, left <-> right. The RTL function of fixed columns is supported in v2.31
The title of the table should clearly make the user perceive the purpose of the table;
Add descriptions to complex tables to provide users with more contextual information about the table;
use sentence case;
Column headers
Keep column headings concise, it is recommended to use 1-2 words as column headings;
When the column header is long, it is recommended to display it in 2 lines, and the remaining text is abbreviated and displayed completely in the Tooltip;
Clicking the row selection button on the second page will jump to the first page?
After the Table's dataSource is updated, the page number will be reset to the initial state. Please check if the data source changed when the component was rendered.
function App() {
const [dataSource, setDataSource] = useState([]);
useEffect(() => {
// ✅ Correct
const getData = () => {
// fetch data
const newData = fetch(/**/);
// set data
setDataSource(dataSource);
};
getData();
}, []);
// ❌ Error
const data = [];
return <Table dataSource={data} columns={[/*...*/]} />;
}
The number of filtered data is wrong?
Please check that your filter columns and data sources are configured correctly.
The filter column needs to set an independent dataIndex, and the dataSource needs to set an independent key. Please refer to the dataSource API. Otherwise the filtering function will not work properly.
Why is the table data not updated?
At present, all parameters of the table component are shallow comparison. That is to say, if the parameter value type is an array or object, you need to manually change its reference to trigger the update. Similarly, if you don't want to trigger additional updates, try not to use literal values when passing parameters directly or define reference parameter values in the render process:
The above writing method will trigger the update of data in the table every time render (the current selected row will be cleared and the row key array will be expanded, etc.). In order to improve performance and avoid some exceptions, please define some reference type parameters outside the render method as far as possible (if hooks are used, please use useMemo or useState for storage).**
Why can't my form line be selected and expanded?
Please specify a rowKey or set a different "key" attribute for each item of the dataSource. All rows related operations in the table need to be used.
How to implement custom sorting or pass parameters to the server for sorting when clicking the sort button?
The input parameters of the onChange method include pagination, filters, and sorter. Users can customize the sorting of the dataSource according to the sorter.
How to add className to a row?
Use onRow or onHeaderRow.
How to style the table cell?
It can be controlled by column.onHeaderCell and column.onCell.
Why cache the previously selected keys for the first parameter of rowSelectiononChange?
This is for the scenario where the selected row keys are lost when data is selected on the first page during paging, and then the data is selected on the second page. If you don't want to use the cached keys, you can filter it from the current dataSource or use the second parameter of rowSelectiononChange.
Does it support single row selection?
Table currently does not support single-row selection function, and users can implement single selection in a custom way. Please check the FAQ.
How is Table implemented, I want to know more details?