Table
Table 表格
代码示例
import { BfTable } from '@bud-fe/react-taro-ui';import type { ColumnsType } from '@bud-fe/react-taro-ui/es/components/bf-table';import { View } from '@tarojs/components';import React, { useState } from 'react';const dataSource = [{id: 1,type: '店内执行',progress: '未完成',time: '22-07-12',object: (<View>共 <text style={{ color: '#FD3C42' }}>10</text> 个对象</View>),},{ id: 2, type: '卖进', progress: '已完成', time: '22-07-12' },{ id: 3, type: '先锋购', progress: '已完成', time: '22-07-12' },];export default () => {const [editingColumn, setEditingColumn] = useState<ColumnsType>();const [editDataSource, setEditDataSource] = useState(dataSource);const columns: ColumnsType[] = [{ title: '分类', dataIndex: 'type', key: 'type', width: 176, fixed: true, borderRight: true },{ title: '进度', dataIndex: 'progress', key: 'progress', width: 152 },{ title: '截止时间', dataIndex: 'time', key: 'time', width: 192 },{ title: '对象', dataIndex: 'object', key: 'object', width: 256 },];const editColumns: ColumnsType[] = [{ title: '分类', dataIndex: 'type', key: 'type', width: 176, fixed: true, borderRight: true },{ title: '进度', dataIndex: 'progress', key: 'progress', width: 152 },{title: '截止时间',dataIndex: 'time',key: 'time',width: 200,editable: true,editType: 'text',handleSave: async (record, value, index) => {console.log('handleSave', { record, value, index });setEditingColumn(undefined);setEditDataSource((pre) => {pre[index] = record;return [...pre];});return true;},},{ title: '对象', dataIndex: 'object', key: 'object', width: 256 },];return (<><View className="group-title">基础用法</View><BfTable rowKey="id" columns={columns} dataSource={dataSource} /><View className="group-title">plain</View><BfTable rowKey="id" plain columns={columns} dataSource={dataSource} /><View className="group-title">可编辑&带边框</View><BfTablerowKey="id"borderedcolumns={editColumns}dataSource={editDataSource}editingColumn={editingColumn}onColumnEdit={(col) => setEditingColumn(col)}/></>);};
API
属性名 | 描述 | 类型 | 默认值 |
---|---|---|---|
columns | 表格列的配置描述 | ColumnsType[] | (必选) |
rowKey | 表格行 key 的取值 | string | (必选) |
dataSource | 数据数组 | any[] | (必选) |
showHeader | 是否展示首行(默认true) | boolean | -- |
showNestedHeader | 是否展示嵌套的表格头样式(默认false) | boolean | -- |
bordered | 是否展示列边框(默认false) | boolean | -- |
plain | 是否行展示纯白且无分割线(默认false) | boolean | -- |
onColumnEdit | 列点击编辑事件触发 | (col: ColumnsType) => void | -- |
editingColumn | 正在编辑的列 | ColumnsType | -- |
reverseBg | 是否反转红白背景色(默认false) | boolean | -- |
fixedPadding | 嵌套表格固定padding避免错位(默认false) | boolean | -- |