1.0.0-beta.12 • Published 5 years ago

@rax-ui/table v1.0.0-beta.12

Weekly downloads
6
License
-
Repository
-
Last release
5 years ago

display: Table

family: Data Display

Table

表格,展示行列数据

API

Props

参数说明类型默认值
bordered是否展示外边框和列边框booleanfalse
columns表格列的配置描述,具体项见下表array-
dataSource数据数组array-
sortDirections支持的排序方式,取值为 'ascend' 'descend' null,设置在 table props 上对所有列生效Array'ascend', 'descend', null
customStyles可自定义所有样式Function(defaultStyles):object-
onHeaderRow设置头部行属性Function(column, index)-
onRow设置行属性Function(record, index)-
sortIconRender排序icon renderFunction(column, sortOrder) {}-
descIconRender字段说明icon renderFunction(column)
onClickDescIcon自定义字段说明icon点击事件Function(column, event)
rowKey(暂未支持)表格行 key 的取值,可以是字符串或一个函数string / Function(record):string'key'
onChange排序变化时触发Function(sorter)

Column Props

列描述数据对象,是 columns 中的一项。

参数说明类型默认值
align设置列内容的对齐方式'left' / 'right' / 'center''left'
colSpan表头列合并,设置为 0 时,不渲染(暂未支持)number1
dataIndex列数据在数据项中对应的 keystring-
fixed列是否固定(固定列需通过customStyles设置fixedTable.left(默认为20)为表格和屏幕左边的距离,详见demo用法)booleanfalse
keyReact 需要的 key,如果已经设置了唯一的 dataIndex,可以忽略这个属性string-
render生成复杂数据的渲染函数,参数分别为当前行的值,当前行数据,行索引,@return里面可以设置表格行/列合并Function(text, record, index) {}-
defaultSortOrder默认排序顺序'ascend' / 'descend'-
sortOrder排序的受控属性,外界可用此控制列的排序,可设置为 'ascend' 'descend'string-
sorter排序函数,本地排序使用一个函数(参考 Array.sort 的 compareFunction),需要服务端排序可设为 trueFunction / boolean-
sortDirections支持的排序方式,取值为 'ascend' 'descend' nullArray'ascend', 'descend', null
title列头显示文字string-
width列宽度number-
onCell设置单元格属性Function(record, rowIndex)-
onHeaderCell设置头部单元格属性Function(column)-
children子列array,其中元素是column对象-

onRow 用法

适用于 onRow onHeaderRow onCell onHeaderCell

<Table
  onRow={(record) => {
    return {
      onClick: (event) => {},       // 点击行
      onLongPress: (event) => {},   // 长按行,H5不支持
      onAppear: (event) => {},
      onDisappear: (event) => {},
      customStyle: (defaultStyle) => {},         // 设置自定义样式

      // 仅适用于onCell、onHeaderCell
      titleCustomStyle: (defaultStyle) => {},    // 设置标题的自定义样式,
    };
  }}
  onHeaderRow={(column) => {
    return {
      onClick: () => {},        // 点击表头行
    };
  }}
/>

注意

按照 React 的规范,所有的组件数组必须绑定 key。在 Table 中,dataSourcecolumns 里的数据值都需要指定 key 值。对于 dataSource 默认将每列数据的 key 属性作为唯一的标识。

如果你的数据没有这个属性,务必使用 rowKey 来指定数据列的主键。若没有指定,控制台会出现以下的提示,表格组件也会出现各类奇怪的错误。

控制台警告

// 比如你的数据主键是 uid
return <Table rowKey="uid" />;
// 或
return <Table rowKey={record => record.uid} />;