npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rax-ui/table

v1.0.0-beta.12

Published

--- display: Table family: Data Display ---

Downloads

7

Readme


display: Table family: Data Display

Table

表格,展示行列数据

API

Props

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | bordered | 是否展示外边框和列边框 | boolean | false | | 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 render | Function(column, sortOrder) {} | - | | descIconRender | 字段说明icon render | Function(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 时,不渲染(暂未支持) | number | 1 | | dataIndex | 列数据在数据项中对应的 key | string | - | | fixed | 列是否固定(固定列需通过customStyles设置fixedTable.left(默认为20)为表格和屏幕左边的距离,详见demo用法) | boolean | false | | key | React 需要的 key,如果已经设置了唯一的 dataIndex,可以忽略这个属性 | string | - | | render | 生成复杂数据的渲染函数,参数分别为当前行的值,当前行数据,行索引,@return里面可以设置表格行/列合并 | Function(text, record, index) {} | - | | defaultSortOrder | 默认排序顺序 | 'ascend' / 'descend' | - | | sortOrder | 排序的受控属性,外界可用此控制列的排序,可设置为 'ascend' 'descend' | string | - | | sorter | 排序函数,本地排序使用一个函数(参考 Array.sort 的 compareFunction),需要服务端排序可设为 true | Function / boolean | - | | sortDirections | 支持的排序方式,取值为 'ascend' 'descend' null | Array | ['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} />;