{"id":13805482,"url":"https://github.com/NewbeeFE/antd-data-table","last_synced_at":"2025-05-13T19:31:13.374Z","repository":{"id":37664964,"uuid":"101040041","full_name":"NewbeeFE/antd-data-table","owner":"NewbeeFE","description":"A component that combines antd's Table and Form to do the search, display, and operating jobs for data.","archived":false,"fork":false,"pushed_at":"2019-10-29T14:47:14.000Z","size":1933,"stargazers_count":126,"open_issues_count":16,"forks_count":24,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-11-18T21:47:51.332Z","etag":null,"topics":["antd","react","react-form-component","storybook"],"latest_commit_sha":null,"homepage":"https://newbeefe.github.io/antd-data-table/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NewbeeFE.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-22T08:26:35.000Z","updated_at":"2024-08-12T00:53:41.000Z","dependencies_parsed_at":"2022-09-09T04:01:31.344Z","dependency_job_id":null,"html_url":"https://github.com/NewbeeFE/antd-data-table","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewbeeFE%2Fantd-data-table","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewbeeFE%2Fantd-data-table/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewbeeFE%2Fantd-data-table/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NewbeeFE%2Fantd-data-table/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NewbeeFE","download_url":"https://codeload.github.com/NewbeeFE/antd-data-table/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254012968,"owners_count":21999346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["antd","react","react-form-component","storybook"],"created_at":"2024-08-04T01:01:01.587Z","updated_at":"2025-05-13T19:31:12.391Z","avatar_url":"https://github.com/NewbeeFE.png","language":"TypeScript","readme":"# antd-data-table\n\n[![npm](https://img.shields.io/npm/dm/antd-data-table.svg)](https://www.npmjs.com/package/antd-data-table)\n[![npm](https://img.shields.io/npm/v/antd-data-table.svg)](https://www.npmjs.com/package/antd-data-table)\n[![Build Status](https://travis-ci.org/NewbeeFE/antd-data-table.svg?branch=master)](https://travis-ci.org/NewbeeFE/antd-data-table)\n[![antd](https://img.shields.io/badge/antd-v2.x-yellowgreen.svg)](https://github.com/ant-design/ant-design)\n\nA component that combines antd's Table and Form to do the search, display, and operating jobs for data.\n\n![](https://user-images.githubusercontent.com/914329/29578209-0af170f4-87a1-11e7-95d0-1b00a141b581.png)\n\n## Feature\n\nFree from:\n\n- Handling pagination\n- Handling table row selection\n- Writing search field form item components\n- Writing row actions components\n\nJust focus on:\n\n- Doing the data fetching request and return the data\n- Rendering a specific data field if needed\n- Writing plugin to operate one or many data object(s)\n\n## Install\n\n```bash\n$ yarn add antd-data-table --save\n```\n\n## Simplest data table\n\n[Demo](https://newbeefe.github.io/antd-data-table/?selectedKind=DataTable\u0026selectedStory=basic)\n\n```tsx\nimport { DataTable } from 'antd-data-table'\n\nconst searchFields: SearchField[] = [\n  {\n    label: 'ID',\n    name: 'id',\n    type: 'input',\n    payload: {\n      props: {\n        placeholder: 'placeholder'\n      }\n    }\n  },\n  {\n    label: 'Select',\n    name: 'select',\n    type: 'select',\n    payload: {\n      options: [\n        { key: '1', label: 'one', value: '1' },\n        { key: '2', label: 'two', value: '2' },\n        { key: '3', label: 'three', value: '3' }\n      ]\n    }\n  }\n]\n\nconst columns: TableColumnConfig\u003cany\u003e[] = [\n  {\n    key: 'id',\n    title: 'ID',\n    dataIndex: 'id'\n  }, {\n    key: 'title',\n    title: 'Title',\n    dataIndex: 'title'\n  }\n]\n\nconst expands: Expand[] = [\n  {\n    title: 'Body',\n    dataIndex: 'body',\n    render (value) {\n      return value \u0026\u0026 `${value.substr(0, 100)} ...`\n    }\n  },\n  {\n    title: 'User ID',\n    dataIndex: 'userId'\n  }\n]\n\nconst onSearch = async ({ page, pageSize, values }) =\u003e {\n  const res = await axios.get('http://jsonplaceholder.typicode.com/posts', {\n    params: {\n      _page: page,\n      _limit: pageSize,\n      ...values\n    }\n  })\n  return {\n    dataSource: res.data,\n    total: Number(res.headers['x-total-count'])\n  }\n}\nrender(\n  \u003cDataTable\n    rowKey={record =\u003e record.id}\n    searchFields={searchFields}\n    initialColumns={columns}\n    initialExpands={expands}\n    onSearch={onSearch}\n  /\u003e\n, mountNode)\n```\n\n## Guide\n\n### Collapsable search field\n\nSometimes there are many search fields, you could set a `maxVisibleFieldCount` to automatically have a collapsable form:\n\n[Demo](https://newbeefe.github.io/antd-data-table/?selectedKind=DataTable\u0026selectedStory=maxVisibleFieldCount)\n\n```diff\nimport { DataTable } from 'antd-data-table'\n\nrender(\n  \u003cDataTable\n    rowKey={record =\u003e record.id}\n    searchFields={searchFields}\n    initialColumns={columns}\n    onSearch={onSearch}\n+   maxVisibleFieldCount={4}\n  /\u003e\n, mountNode)\n```\n\n### Row actions\n\nWe usually need to write some action buttons for operating a specific record. `antd-data-table` made it super easy:\n\n[Demo](https://newbeefe.github.io/antd-data-table/?selectedKind=DataTable\u0026selectedStory=rowActions)\n\n```tsx\nconst actions: RowAction[] = [\n  {\n    label: 'Edit',\n    action (record) {\n      action('onClick edit')(record)\n    }\n  },\n  {\n    label: 'More',\n    children: [\n      {\n        label: 'Remove',\n        action (record) {\n          action('onClick remove')(record)\n        }\n      },\n      {\n        label: 'Open',\n        action (record) {\n          action('onClick open')(record)\n        }\n      }\n    ]\n  }\n]\n\nrender(\n  \u003cDataTable\n    rowKey={record =\u003e record.id}\n    searchFields={searchFields}\n    initialColumns={columns}\n    initialExpands={expands}\n    onSearch={onSearch}\n    actions={actions}\n  /\u003e\n, mountNode)\n```\n\n### Plugins\n\nPlugins are for operating multiple records. Every plugin will render a component at the top of table.\n\n[Demo](https://newbeefe.github.io/antd-data-table/?selectedKind=DataTable\u0026selectedStory=plugins)\n\nLet's write a simplest plugin: A button that show current selected rows' ids:\n\n```tsx\nconst ShowIdsBtn = ({ selectedRows, clearSelection }) =\u003e {\n  const showIds = () =\u003e {\n    message.info(selectedRows.map(row =\u003e row.id).join(','))\n    // clear selection after the action is done\n    clearSelection()\n  }\n\n  return \u003cButton onClick={showIds}\u003eShow Ids\u003c/Button\u003e\n}\n\nconst plugins = [\n  renderer (selectedRowKeys, selectedRows, clearSelection) {\n    return \u003cShowIdsBtn selectedRows={selectedRows} clearSelection={clearSelection} /\u003e\n  }\n]\n\nrender (\n  \u003cDataTable\n    rowKey={record =\u003e record.id}\n    searchFields={searchFields}\n    plugins={plugins}\n    initialColumns={columns}\n    initialExpands={expands}\n    onSearch={onSearch}\n  /\u003e\n, mountNode)\n```\n\n## Props\n\n### name?: string\n\nUnique table name.\n\n### `rowKey`: (record) =\u003e string\n\nThe `key` value of a row. \n\n### `searchFields: SearchField[]`\n\nSearchField is an object that contains:\n\n- **label: string** Pass to `\u003cForm.Item\u003e`'s `label` property.\n- **name: string** Pass to `getFieldDecorator` as the decorator name.\n- **type?: RenderType** antd-data-table comes with some common form item type. Such as `input`, `select`.\n- **initialValue?: any** Inital form value.\n- **renderer?: (payload?: object) =\u003e React.ReactNode** When the form item types are not statisfied, your could write your own renderer. the `ReactNode` that returned will be wrapped by `getFieldDecorator`.\n- **validationRule?: ValidateionRule[]** antd validation rules. Pass to `getFieldDecorator(name, { rules })`.\n- **payload?: { props: any, [key: string]: any }** Some params that pass to the renderer.\n- **span?: number** Form Item Col span value. 6 by default.\n\n#### out of the box render type\n\n##### input\n\n```ts\ninterface payload {\n  props: object // antd Input props\n}\n```\n\n#### datePicker\n\n```ts\ninterface payload {\n  props: object // antd DatePicker props\n}\n```\n\n#### treeSelect\n\n```ts\ninterface payload {\n  props: object // antd TreeSelect props\n}\n```\n\n##### select\n\n```ts\ninterface payload {\n  props: object, // antd Select props\n  options: {\n    key: string,\n    label: string,\n    value: string\n  }[]\n}\n```\n\n### `initialColumns: TableColumnConfig[]`\n\nantd's TableColumnConfig. See more at https://ant.design/components/form/\n\n### `initialExpands: Expand[]`\n\n```ts\ntype Expand = {\n  /** Title of this column **/\n  title: string,\n  /** Display field of the data record, could be set like a.b.c **/\n  dataIndex: string,\n  /** Renderer of the column in the expanded. The return value should be a ReactNode **/\n  render?: (text: any, record?: {}) =\u003e React.ReactNode\n}\n```\n\n### `onSearch\u003cT\u003e (info: SearchInfo): Promise\u003cSearchResponse\u003cT\u003e\u003e`\n\n`onSearch` property need a function that return a Promise, which resolves an object that contains `total` and `dataSource`. This function receive a `SearchInfo`:\n\n```ts\ntype SearchInfo = {\n  /** values from `getFieldsValue()` */\n  values: any,\n  /** current page */\n  page: number,\n  /** page size */\n  pageSize: number\n}\n```\n\n### `title?: React.ReactNode`\n\n### `searchBtnText?: string`\n\n### `clearBtnText?: string`\n\n### `listSelectionBtnText?: string`\n\n### `onError? (err): void`\n\nError handler that trigger when onSearch throw error.\n\n### `loadDataImmediately?: boolean`\n\nLoad list data immediately, default is false\n\n### `onValidateFailed?: (err: ValidateError) =\u003e void`\n\nForm validation failed handler\n\n### `pageSize?: number`\n\ndefault is 10\n\n### `plugins?: Plugin[]`\n\n### `rowActions?: RowAction[]`\n\n### `enableListSelection?`: boolean\n\nIf `true`, a list selection button will display on table title.\n\n*Be sure to pass the `name` props if it is enable.*\n\n### `rowSelection?`: TableRowSelection\n\nCustom `rowSelection`.\n\n### `affixTarget?`: () =\u003e HTMLelement\n\nFor `Affix`. Specifies the scrollable area dom node\n\n### `affixOffsetTop?`: number\n\nPixels to offset from top when calculating position of scroll\t\n\n### `affixOffsetBottom?`: number\n\nPixels to offset from bottom when calculating position of scroll\t\n\n## FAQ\n\n### How to trigger the `onSearch` action imperatively?\n\nThere is a public `fetch` method in DataTable to do this action. So you could get it from `ref`:\n\n[Demo](https://newbeefe.github.io/antd-data-table/?selectedKind=DataTable\u0026selectedStory=customSearch)\n\n```jsx\n// ...\nrender () {\n  let dataTableRef: DataTable | null = null\n\n  const saveDataTableRef = (ref: DataTable) =\u003e {\n    dataTableRef = ref\n  }\n\n  const onClickCustomSearch = () =\u003e {\n    if (dataTableRef) {\n      dataTableRef.fetch(1)\n    }\n  }\n\n  return (\n    \u003cdiv style={{ padding: '1em' }}\u003e\n      \u003cDataTable\n        ref={saveDataTableRef}\n        name='customSearch'\n        rowKey={record =\u003e record.id}\n        searchFields={searchFields}\n        initialColumns={columns}\n        initialExpands={expands}\n        onSearch={onSearch}\n        pageSize={10}\n        onError={onError}\n      /\u003e\n      \u003cButton onClick={onClickCustomSearch}\u003eCustom Search\u003c/Button\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n`fetch: async (page: number, values: object = this.state.currentValues, clearPagination: boolean = false)`\n\n## Build\n\n```bash\n$ yarn\n\n$ yarn start # start the storybook\n\n$ yarn test # run the test\n\n$ yarn run build # build the distribution file\n\n$ yarn run build:storybook # build storybook\n```\n\n### Release workflow\n\n```bash\n$ yarn run build:storybook # build storybook\n\n$ npm publish\n```\n\n# License\n\nMIT License\n","funding_links":[],"categories":["Components"],"sub_categories":["Themes"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNewbeeFE%2Fantd-data-table","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNewbeeFE%2Fantd-data-table","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNewbeeFE%2Fantd-data-table/lists"}