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

@monsterooo/table

v1.4.3

Published

table

Downloads

1

Readme


title: Table 表格 nav: title: 组件 path: /components order: 1 group: title: ' ' order: 120

Table 表格

展示行列数据。

使用

import Table from '@monsterooo/table';

<Table />;

代码演示

基本用法

扩展渲染类型

表头过滤

API

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | fields | 表格列属性配置。具体属性见TableField | TableField[] | - | | nextFields | 动态修改 fields 中渲染节点的属性 | TableField[] | - | | fieldTypes | 扩展 fields 中渲染类型,可覆盖内置的基本渲染类型,请注意 type 命名 | { [type: string]: (props: object) => React.ReactNode} | - | | emptyRender | 空值渲染函数,默认将undefinednull''渲染为'--' | (value: any) => React.ReactNode | - | | data | 数据源,同 table 的 dataSource | array | [] | | total | 数据总量,pagination 的 total | number | 0 | | columnFilter | 是否开启表头显示列过滤 | boolean | false | | columnFilterKey | 表头显示列过滤的操作按钮挂载的 column 的 key,默认为'action',即操作栏 | string | action | | toolbar | 用于渲染操作栏 | ReactNode | - | | toolbarPosition | 操作拦内容渲染位置 | left|right | left |

其他属性见 antd Table

TableField

| 参数 | 说明 | 类型 | 默认值 | | --- | --- | --- | --- | | key | 表格列唯一标识 | string | - | | name | 列头显示文字, 同 Column title | ReactNode | - | | type | 渲染类型,包括基本渲染类型或自定义。 | string | - | | columnFilterItemName | columnFilter 展示的列名称 | string | - | | visible | 控制列的显示隐藏 | boolean | true | | props | 用于对应 type 的函数或者组件传递属性参数 | object | (value, record, index) => object | - |

其他属性见 antd Table Column

基本渲染类型

可通过 fieldTypes 注入其他自定义类型。形如

fieldTypes: {
  // value, index为内部注入的属性
  customed: ({ value, index, ...otherProps }) => (
    <CustomedSome {...otherProps} />
  );
  unit: ({ value }) => `${value}元`;
}

其中 props 有自动注入{ value: xx, index: xx }(value 为当前表格的值,index 为行序号,从 0 开始)。当然你可以通过 type 返回函数的形式覆盖这两个属性。建议自定义的组件或者函数的一些操作可以直接基于 value 进行。

内置的基本类型如下

| Type | 说明 | | ---------- | ---------------------------- | | action | 表格操作项 | | avatar | 用户头像 | | index | 表格行序号 | | enums | 枚举值转化 | | date | YYYY-MM-DD 日期格式 | | datetime | YYYY-MM-DD HH:mm:ss 日期格式 | | time | HH:mm:ss 时间格式 |

FAQ

为 widgets 配置公共属性

自定义渲染类型的组件如果使用useWidgetProps处理了 props, 可以通过 ConfigProvider 的widgets属性配置公共属性

import { useWidgetProps } from '@monsterooo/hooks';
const combineProps = useWidgetProps(type, props);

用法见 扩展渲染类型