1.0.25 • Published 4 years ago

antd-pro-table-felixfixed v1.0.25

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

中文

🏆 Use Ant Design Table like a Pro!

Demo

codesandbox

API

pro-table is encapsulated in an antd table, supports some presets, and encapsulates some behavior. Only apis different from antd table are listed here.

Table

PropertyDescriptionTypeDefault Value
requesta method to get the dataSource.(params?: {pageSize: number;current: number;[key: string]: any;}) => Promise<RequestData<T>>-
filterDataDo some processing on the data obtained through the url.(data: T[]) => T[]-
defaultDataDefault data array.T[]-
manualWhether manual mode, you need to manually call fetch.boolean-
effectsWhen the dependent parameter changes, the load data is automatically removed.(number \| string \| boolean)[][]
onInitTriggered after the table data is successfully initialized, it will be triggered multiple times.(action: UseFetchDataAction<RequestData<T>>) => void[]
toolBarRenderRender toolbar, support for returning a dom array, will automatically increase margin-right.(action: UseFetchDataAction<RequestData<T>>) => React.ReactNode[]-
onLoadTriggered after the data is loaded, it will be triggered multiple times.(dataSource: T[]) => void-
tableClassNameThe className of the packaged tablestring-
tableStyleThe style of the packaged tableCSSProperties-
optionstable's default operation, set to false to close it{{ fullScreen: boolean \| function, reload: boolean \| function,setting: true }}{{ fullScreen: true, reload:true,setting: true }}
searchwhether to search the formbooleantrue
momentFormatformatting moment type"string" \| "number" \| falsestring
beforeSearchSubmitMake some changes before searching(params:T)=>T-

Columns

PropertyDescriptionTypeDefault Value
renderTextSimilar to table render, but must return string, if you just want to convert the enumeration, you can use this scheme(text: any,record: T,index: number,action: UseFetchDataAction<RequestData<T>>) => string-
renderLike table's render, the first argument becomes dom, and the fourth argument is added.(text: React.ReactNode,record: T,index: number,action: UseFetchDataAction<RequestData<T>>) => React.ReactNode \| React.ReactNode[]-
renderFormIteminput component for rendering query form(item, props: {value, onChange}) => React.ReactNode-
ellipsisWhether to automatically abbreviateboolean-
copyableWhether to support replicationboolean-
valueEnumThe enumeration of values will automatically convert the value as a key to get the content to be displayed{key: string: React.ReactNode}-
valueTypeType of value'money' \| 'option' \| 'date' \| 'dateTime' \| 'time' \| 'text'\| 'index' \| 'indexBorder''text'
hideInSearchDo not show this in the query formboolean-
hideInTableDo not show this column in Tableboolean-

valueType

  • money conversion value is the amount of eg. ¥10,000.26
  • date date eg. 2019-11-16
  • dateTime date and time eg. 2019-11-16 12:50:00
  • time time eg. 12:50:00
  • option operation item, it will automatically increase marginRight, only one array is supported.
  • text default value, no processing

valueEnums

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 ProTable, { ProColumns } from '@ant-design/pro-table';

const columns: ProColumns[] = [
  {
    title: 'Name',
    dataIndex: 'name',
    copyable: true,
  },
  {
    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>,
    ],
  },
];

export default () => (
  <ProTable
    size="small"
    columns={columns}
    url={request}
    rowKey="key"
    params={{}}
    toolBarRender={action => [
      <Input.Search
        style={{
          width: 200,
        }}
        onSearch={value => setKeyword(value)}
      />,
      <Button
        onClick={() => {
          action.reload();
        }}
        type="primary"
        style={{
          marginRight: 8,
        }}
      >
        reload
      </Button>,
    ]}
  />
);

LICENSE

MIT