0.0.655 • Published 6 months ago

@bmstravel/nvp-pro-table v0.0.655

Weekly downloads
-
License
MIT
Repository
-
Last release
6 months ago

English

🏆 Use Ant Design Table like a Pro!

Demo

codesandbox

API

pro-table 在 antd 的 table 上进行了一层封装,支持了一些预设,并且封装了一些行为。这里只列出与 antd table 不同的 api。

Table

属性描述类型默认值
request一个获得 dataSource 的方法(params?: {pageSize: number;current: number;[key: string]: any;}) => Promise<RequestData<T>>-
postData对通过 url 获取的数据进行一些处理(data: T[]) => T[]-
defaultData默认的数据T[]-
actionRefget table actionReact.MutableRefObject<ActionType> \| ((actionRef: ActionType) => void)-
toolBarRender渲染工具栏,支持返回一个 dom 数组,会自动增加 margin-right(action: UseFetchDataAction<RequestData<T>>) => React.ReactNode[]-
onLoad数据加载完成后触发,会多次触发(dataSource: T[]) => void-
onRequestError数据加载失败时触发(e: Error) => void-
tableClassName封装的 table 的 classNamestring-
tableStyle封装的 table 的 styleCSSProperties-
headerTitle左上角的 titleReact.ReactNode-
optionstable 的工具栏,设置为 false 可以关闭它{{ fullScreen: boolean \| function, reload: boolean \| function,setting: true }}{ fullScreen: true, reload:true, setting: true}
search是否显示搜索表单,传入对象时为搜索表单的配置search configtrue
dateFormattermoment 的格式化方式"string" \| "number" \| falsestring
beforeSearchSubmit搜索之前进行一些修改(params:T)=>T-
onSizeChangetable 尺寸发生改变(size: 'default' | 'middle' | 'small' | undefined) => void-
columnsStateMapcolumns 的状态枚举{[key: string]: { show:boolean, fixed: "right"|"left"} }-
onColumnsStateChangecolumns 状态发生改变(props: {[key: string]: { show:boolean, fixed: "right"|"left"} }) => void-
typepro-table 类型"form"-
formantd form 的配置FormProps-

search

属性描述类型默认值
searchText查询按钮的文本string查询
resetText重置按钮的文本string重置
submitText提交按钮的文本string提交
collapseRender收起按钮的 render(collapsed: boolean,showCollapseButton?: boolean,) => React.ReactNode-
collapsed是否收起boolean-
onCollapse收起按钮的事件(collapsed: boolean) => void;-
optionRender操作栏的 render(( searchConfig: Omit<SearchConfig, 'optionRender'>, props: Omit<FormOptionProps, 'searchConfig'>, ) => React.ReactNode) \| false;-

Columns

Tài sảnMô tảLoạiGiá trị mặc định
renderTextvalueEnum(text: any,record: T,index: number,action: UseFetchDataAction<RequestData<T>>) => string-
render(text: React.ReactNode,record: T,index: number,action: UseFetchDataAction<RequestData<T>>) => React.ReactNode \| React.ReactNode[]-
renderFormItem(item,props:{value,onChange}) => React.ReactNode-
ellipsistự động thu nhỏboolean-
copyablecho phép copyboolean-
valueEnumliệt kê giá trị tự động chuyển đổi giá trị theo key để truy xuất nội dung sẽ được hiển thịvalueEnum-
valueType'money' \| 'option' \| 'date' \| 'dateTime' \| 'time' \| 'text'\| 'index' \| 'indexBorder''text'
hideInSearchboolean-
hideInTableboolean-
hideInFormẩn Form tìm kiếmboolean-
filterstrue sẽ lấy filter dựa trên valueEnum được cung cấpboolean \| object[]false
orderthứ tự xuất hiệnnumber-
formItemPropscustom formItem{ [prop: string]: any }-

ActionType

有些时候我们要触发 table 的 reload 等操作,action 可以帮助我们做到这一点。

interface ActionType {
  reload: () => void;
  fetchMore: () => void;
  reset: () => void;
  reloadAndRest: () => void;
}

const ref = useRef<ActionType>();

<ProTable actionRef={ref} />;

// 刷新
ref.current.reload();

// 重置所有项并刷新
ref.current.reloadAndRest();

// 加载更多
ref.current.fetchMore();

// 重置到默认值
ref.current.reset();

// 清空选中项
ref.current.clearSelected();

valueType

现在支持的值如下

类型描述示例
money转化值为金额¥10,000.26
date日期2019-11-16
dateRange日期区间2019-11-16 2019-11-18
dateTime日期和时间2019-11-16 12:50:00
dateTimeRange日期和时间区间2019-11-16 12:50:00 2019-11-18 12:50:00
time时间12:50:00
option操作项,会自动增加 marginRight,只支持一个数组,表单中会自动忽略[<a>操作a</a>,<a>操作b</a>]
text默认值,不做任何处理-
textarea与 text 相同, form 转化时会转为 textarea 组件-
index序号列-
indexBorder带 border 的序号列-
progress进度条-
digit单纯的数字,form 转化时会转为 inputNumber-

valueEnum

当前列值的枚举

interface IValueEnum {
  [key: string]:
    | React.ReactNode
    | {
        text: React.ReactNode;
        status: 'Success' | 'Error' | 'Processing' | 'Warning' | 'Default';
      };
}

Usage

npm install @ant-design/pro-table
# or
yarn add @ant-design/pro-table
import React, { useState } from 'react';
import ProTable, { ProColumns } from '@ant-design/pro-table';
import { Input, Button } from 'antd';

const columns: ProColumns[] = [
  {
    title: 'Name',
    dataIndex: 'name',
    copyable: true,
  },
  {
    title: 'Age',
    dataIndex: 'age',
  },
  {
    title: 'date',
    dataIndex: 'date',
    valueType: 'date',
  },
  {
    title: 'option',
    valueType: 'option',
    dataIndex: 'id',
    render: (text, row, index, action) => [
      <a
        onClick={() => {
          window.alert('确认删除?');
          action.reload();
        }}
      >
        delete
      </a>,
      <a
        onClick={() => {
          window.alert('确认刷新?');
          action.reload();
        }}
      >
        reload
      </a>,
    ],
  },
];

export default () => {
  const [keywords, setKeywords] = useState('');
  return (
    <ProTable<{}, { keywords: string }>
      size="small"
      columns={columns}
      request={() => ({
        data: [
          {
            name: 'Jack',
            age: 12,
            date: '2020-01-02',
          },
        ],
        success: true,
      })}
      rowKey="name"
      params={{ keywords }}
      toolBarRender={(action) => [
        <Input.Search
          style={{
            width: 200,
          }}
          onSearch={(value) => setKeywords(value)}
        />,
      ]}
      pagination={{
        defaultCurrent: 10,
      }}
    />
  );
};

LICENSE

MIT

0.0.634

7 months ago

0.0.62

8 months ago

0.0.655

6 months ago

0.0.633

7 months ago

0.0.63

7 months ago

0.0.654

6 months ago

0.0.64

7 months ago

0.0.632

7 months ago

0.0.653

6 months ago

0.0.65

7 months ago

0.0.631

7 months ago

0.0.638

7 months ago

0.0.637

7 months ago

0.0.636

7 months ago

0.0.635

7 months ago

0.0.652

7 months ago

0.0.651

7 months ago

0.0.645

7 months ago

0.0.644

7 months ago

0.0.622

7 months ago

0.0.643

7 months ago

0.0.621

7 months ago

0.0.642

7 months ago

0.0.649

7 months ago

0.0.647

7 months ago

0.0.646

7 months ago

0.0.641

7 months ago

0.0.639

7 months ago

0.0.61

11 months ago

0.0.6

12 months ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago