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 🙏

© 2025 – Pkg Stats / Ryan Hefner

amos-table

v2.0.12

Published

amos table

Readme

Table 表格

展示行列数据。

何时使用

  • 当有大量结构化的数据需要展现时;
  • 当需要对数据进行排序、搜索、分页、自定义操作等复杂行为时。

如何使用

指定表格的数据源 dataSource 为一个数组。

const dataSource = [
  {
    key: '1',
    name: 'ilex',
    age: 16,
    address: '雁塔区电子城街道'
  },
  {
    key: '2',
    name: 'ray',
    age: 18,
    address: '长安区郭杜街道'
  },
  {
    key: '3',
    name: 'iray',
    age: 18,
    address: '曲江'
  }
];

const columns = [
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '年龄',
    dataIndex: 'age',
    key: 'age'
  },
  {
    title: '住址',
    dataIndex: 'address',
    key: 'address'
  }
];

<Table dataSource={dataSource} columns={columns} />

API

Table

| params | type | default | description | | ------ | ------ | ------ | ------ | | rowSelection | Object | null | 列表项是否可选择,配置项 | | pagination | Object | | 分页器,配置项参考 pagination,设为 false 时不显示分页 | | size | String | default | 正常或迷你类型,default or small | | dataSource | Array | | 数据数组 | | columns | Array | - | 表格列的配置描述,具体项见下表 | | rowKey | String or Function(record, index):string | 'key' | 表格行 key 的取值,可以是字符串或一个函数 | | rowClassName | Function(record, index):string | - | 表格行的类名 | | expandedRowRender | Function | - | 额外的展开行 | | defaultExpandedRowKeys | Array | - | 默认展开的行 | | expandedRowKeys | Array | - | 展开的行,控制属性 | | onChange | Function(pagination, filters, sorter) | | 分页、排序、筛选变化时触发 | | loading | Boolean | false | 页面是否加载中 | | locale | Object | filterConfirm: '确定', filterReset: '重置', emptyText: '暂无数据' | 默认文案设置,目前包括排序、过滤、空数据文案 | | indentSize | Number | 15 | 展示树形数据时,每层缩进的宽度,以 px 为单位 | | onRowClick | Function(record, index) | - | 处理行点击事件 | | useFixedHeader | Boolean | false | 是否固定表头 | | bordered | Boolean | false | 是否展示外边框和列边框 | | showHeader | Boolean | true | 是否显示表头 | | footer | Function(currentPageData) | - | 表格底部自定义渲染函数 | | scroll | Object | - | 横向或纵向支持滚动,也可用于指定滚动区域的宽高度:{{ x: true, y: 300 }} |

actionBarProps

| params | type | default | description | | ------ | ------ | ------ | ------ | | showColumnPicker | boolen | false | 是否展示actionbar | | checkboxColumnKey | String | selection-column | 表格checkbox列所在的key | | width |Number | 600 | 宽 | | locale | Object | {customeColumn: '自定义列', more: '更多'} | 本地化 | | defaultColumns | array | - | 不可去掉或隐藏的列,columns dataIndex |

Column

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

| params | type | default | description | | ------ | ------ | ------ | ------ | | title | String or React.Element | - |列头显示文字 | | key | String | - | React 需要的 key,建议设置 | | dataIndex | String | - | 列数据在数据项中对应的 key,支持 a.b.c 的嵌套写法 | | render | Function(text, record, index) {} | - | 生成复杂数据的渲染函数,参数分别为当前行的值,当前行数据,行索引,@return里面可以设置表格行/列合并 | | filters | Array | - |表头的筛选菜单项 | | onFilter | Function | - |本地模式下,确定筛选的运行函数 | | filterMultiple | Boolean | true |是否多选 | | filterDropdown | React.Element | - |可以自定义筛选菜单,此函数只负责渲染图层,需要自行编写各种交互 | | sorter | Function or Boolean | - | 排序函数,本地排序使用一个函数,需要服务端排序可设为 true | | sorterMultiple | Number or null | - | 是否支持多列排序,设置为 null 或者不设置,则不支持多列排序。设置为 具体的 number 时,表示多列排序的优先级 | | colSpan | Number | | 表头列合并,设置为 0 时,不渲染 | | width | String or Number | - | 列宽度 | | className | String | - | 列的 className | | fixed | Boolean or String | false | 列是否固定,可选 true(等效于 left) 'left' 'right' | | filteredValue | Array | - | 筛选的受控属性,外界可用此控制列的筛选状态,值为已筛选的 value 数组 | | sortOrder | Boolean or String | - | 排序的受控属性,外界可用此控制列的排序,可设置为 'ascend' 'descend' false |

rowSelection

选择功能的配置。

| params | type | default | description | | ------ | ------ | ------ |- ------ | | type | String | checkbox | 多选/单选,checkbox or radio | | selectedRowKeys | Array | 指定选中项的 key 数组,需要和 onChange 进行配合 | | onChange | Function(selectedRowKeys, selectedRows) | - | 选中项发生变化的时的回调 | | getCheckboxProps | Function(record) | - | 选择框的默认属性配置 | | onSelect | Function(record, selected, selectedRows) | - | 用户手动选择/取消选择某列的回调 | | onSelectAll | Function(selected, selectedRows, changeRows) | - | 用户手动选择/取消选择所有列的回调 |

pagination

基础表格 pagination

| params | description | type |default | | ------ |------ | ------ | ------ | | current | number | - | 当前页数 | | defaultCurrent | number | 1 | 默认的当前页数 | | total |number | 0 | 数据总数 | | defaultPageSize | number | 10 |默认的每页条数 | | pageSize | number | - | 每页条数 | | onChange | Function(page, pageSize) | noop | 页码改变的回调,参数是改变后的页码及每页条数 | | showSizeChanger | boolean | false | 是否可以改变 pageSize | | pageSizeOptions | string[] / ['10', '20', '30', '40'] | 指定每页可以显示多少条 | | onShowSizeChange | Function(current, size) | noop | pageSize 变化的回调 | | showQuickJumper | boolean | false | 是否可以快速跳转至某页 | | size | string | "" | 当为「small」时,是小尺寸分页 | | simple | boolean | - | 当添加该属性时,显示为简单分页 | | showTotal | Function(total, range) | - | 用于显示数据总量和当前数据顺序 | | itemRender | (page, type: 'page' | 'prev' | 'next') => React.ReactNode | - | 用于自定义页码的结构,可用于优化 SEO |

注意

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

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

设置 key 方式:

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

changelog

  • 2023-10-25 v2.0.7 add Table#sorterMultiple
  • 2020-12-21 v2.0.2 modify table bug
  • 2020-12-21 v2.0.1 modify external class
  • 2020-12-10 v2.0.0 rebuild table