table.stories.jsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. import React from 'react';
  2. import { Table } from '@douyinfe/semi-ui';
  3. import JSXColumnsSimple from './JSXColumnsSmiple';
  4. import JSXColumnsComplex from './JSXColumnsComplex';
  5. import JSXColumnPropColumn from './JSXColumnPropColumn';
  6. import ResizableColumns from './ResizableColumns';
  7. import DragableTableDemo from './DragableTable';
  8. import DynamicTableDemo from './DynamicTable';
  9. import LinkedScroll from './LinkedScroll';
  10. import ModalTable from './ModalTable';
  11. import TabsTable from './TabsTable';
  12. import EventTable from './EventTable';
  13. import FnTable from './FnTable';
  14. import DynamicFilters from './DynamicFilters';
  15. import ResizableTable from './ResizableTable';
  16. import ExpandDemo from './Expand';
  17. import PaginationDemo from './PagintaionTable';
  18. import SelectedRowsDemo from './SelectedRows';
  19. import ChildrenData from './ChildrenData';
  20. import ChildrenDataSelected from './ChildrenDataSelected';
  21. import FixedExpandedRows from './FixedExpandedRows';
  22. import FixedTable from './FixedTable';
  23. import JSXFixedTable from './JSXFixedTable';
  24. import JSXTitles from './JSXTitles';
  25. import CustomFilterDropdownItem from './CustomFilterDropdownItem';
  26. import VirtualizedDemo from './virtualized';
  27. import VirtualizedNotFixed from './VirtualizedNotFixed';
  28. import InfiniteScroll from './InfiniteScroll';
  29. import VirtualTableOnCell from './VirtualTableOnCell';
  30. import {
  31. ControlledSelection,
  32. PerfComplexRender,
  33. PerfContext,
  34. PerfOnRow,
  35. PerfRender,
  36. PerfResizableSelection,
  37. PerfVirtualized,
  38. } from './Perf';
  39. import RenderPagination from './RenderPagination';
  40. import ControlledSortOrder from './ControlledSortOrder';
  41. import FilterWithNewDataTable from './FilterWithNewDataTable';
  42. import ExpandAllRows from './ExpandAllRows';
  43. import ExpandAllGroupRows from './ExpandAllGroupRows';
  44. import ExpandRowByClick from './ExpandRowByClick';
  45. import FixAllColumnsWithoutWidth from './FixAllColumnsWithoutWidth';
  46. import HugeData from "./HugeData"
  47. import RowSelectionRenderCell from './RowSelectionRenderCell';
  48. export default {
  49. title: 'Table'
  50. }
  51. export { default as WithSideSheet } from './WithSideSheet';
  52. export { default as InSideSheet } from './InSideSheet';
  53. export { default as GroupedCols } from './GroupedCols';
  54. export { default as GroupedColsFixed } from './GroupedColsFixed';
  55. export { default as GroupedColsFixedJSX } from './GroupedColsFixedJSX';
  56. export { default as GroupedColsFixedVirtualized } from './GroupedColsFixedVirtualized';
  57. export { default as GroupedColsFixedVirtualizedGroups } from './GroupedColsFixedVirtualizedGroups';
  58. export { default as GroupedRows } from './GroupedRows';
  59. export { default as GroupedRowsFixed } from './GroupedRowsFixed';
  60. export { default as FixedGroups } from './FixedGroups';
  61. export { default as CustomComponents } from './CustomComponents';
  62. export { default as CustomExpandIcons } from './CustomExpandIcons';
  63. export { default as VirtualizedFixedDemo } from './virtualizedFixed';
  64. export { default as VirtualizedGroupedRows } from './VirtualizedGroupedRows';
  65. export { default as VirtualizedDataSelected } from './VritualizedDataSelected';
  66. export { default as VirtualizedDynamicData } from './VirtualizedDynamicData';
  67. export { default as MassiveColumns } from './MassiveColumns';
  68. export { default as ControlledPagination } from './ControlledPagination';
  69. export { default as FulldRenderDemo } from './FullRender';
  70. export { RTLAlignScrollBar, ColumnAlign, Direction } from './RTL';
  71. export { default as JSXAsyncData } from './JSXAsyncData';
  72. export { default as ScrollBar } from './ScrollBar';
  73. export { default as TableSpan } from './TableSpan';
  74. export { default as FixRenderReturnProps } from './FixRenderReturnProps';
  75. export { default as WarnColumnWithoutDataIndex } from './WarnColumnWithoutDataIndex';
  76. export {
  77. DefaultFilteredValue,
  78. FixedColumnsChange,
  79. FixedZIndex,
  80. FixedHeaderMerge,
  81. FixedResizable,
  82. FixedExpandedRow,
  83. FixedMemoryLeak,
  84. FixedOnHeaderRow,
  85. RadioRowSelection,
  86. FixedVirtualizedEmpty,
  87. FixedFilter,
  88. FixedSorter,
  89. StickyHeaderTable,
  90. Fixed1188,
  91. EmptyFilters,
  92. FixedResizableWithForm,
  93. Zebra,
  94. WordBreakNormalTable, WordBreakFixedTable,
  95. EllipsisNormalTable, EllipsisFixedTable, ShowTitleTable,
  96. Fixed1556,
  97. FixedColumnAlign,
  98. FixOnChange,
  99. ColumnResize,
  100. FixedResizableRowSelection,
  101. SorterSortOrder,
  102. FixedPagination,
  103. ShowHeader,
  104. KeepDOM,
  105. SortIcon,
  106. FixedAllDisabledAndSelected,
  107. FeatRenderFilterDropdown,
  108. InputFilter
  109. FixedAllDisabledAndSelected,
  110. FixedRowSelectionHiddenResizable
  111. } from './v2';
  112. export { default as FixSelectAll325 } from './Demos/rowSelection';
  113. // empty table
  114. const emptyColumn = [
  115. {
  116. title: 'Name',
  117. dataIndex: 'name',
  118. fixed: 'left',
  119. render: text => <a>{text}</a>,
  120. },
  121. {
  122. title: 'Age',
  123. dataIndex: 'age',
  124. },
  125. {
  126. title: 'Address',
  127. dataIndex: 'address',
  128. },
  129. ];
  130. const emptyData = [];
  131. export const EmptyTable = () => <Table autoWidth columns={emptyColumn} dataSource={emptyData} />;
  132. EmptyTable.story = {
  133. name: 'empty table',
  134. };
  135. // basic table
  136. const columns = [
  137. {
  138. title: 'Name',
  139. dataIndex: 'name',
  140. width: '30%',
  141. render: text => <a>{text}</a>,
  142. },
  143. {
  144. title: 'combine',
  145. width: '20%',
  146. dataIndex: 'test',
  147. children: [
  148. {
  149. title: 'Age',
  150. width: '20%',
  151. children: [
  152. {
  153. title: 'Age1',
  154. width: '20%',
  155. dataIndex: 'age1',
  156. },
  157. {
  158. title: 'Age2',
  159. width: '20%',
  160. dataIndex: 'age2',
  161. },
  162. ],
  163. },
  164. {
  165. title: 'Key',
  166. width: '20%',
  167. dataIndex: 'key',
  168. },
  169. ],
  170. },
  171. {
  172. title: 'Address',
  173. width: '50%',
  174. dataIndex: 'address',
  175. },
  176. ];
  177. const data = [
  178. {
  179. key: '1',
  180. name: 'John Brown',
  181. age: 32,
  182. age1: 23,
  183. age2: 11,
  184. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  185. },
  186. {
  187. key: '2',
  188. name: 'Jim Green',
  189. age: 42,
  190. age1: 23,
  191. age2: 11,
  192. address: 'London No. 1 Lake Park',
  193. },
  194. {
  195. key: '3',
  196. name: 'Joe Black',
  197. age: 32,
  198. age1: 23,
  199. age2: 11,
  200. address: 'Sidney No. 1 Lake Park',
  201. },
  202. {
  203. key: '4',
  204. name: 'Disabled User',
  205. age: 99,
  206. age1: 23,
  207. age2: 11,
  208. address: 'Sidney No. 1 Lake Park',
  209. },
  210. ];
  211. export const BasicTable = () => <Table columns={columns} dataSource={data} />;
  212. BasicTable.story = {
  213. name: 'basic table',
  214. };
  215. export const SimpleJsx = () => <JSXColumnsSimple />;
  216. SimpleJsx.story = {
  217. name: 'simple jsx',
  218. };
  219. export const ComplexJsx = () => <JSXColumnsComplex />;
  220. ComplexJsx.story = {
  221. name: 'complex jsx',
  222. };
  223. ComplexJsx.parameters = {
  224. chromatic: { disableSnapshot: true },
  225. }
  226. // selection table
  227. // rowSelection object indicates the need for row selection
  228. const rowSelection = {
  229. onChange: (selectedRowKeys, selectedRows) => {
  230. // console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  231. },
  232. getCheckboxProps: record => ({
  233. disabled: record.name === 'Disabled User', // Column configuration not to be checked
  234. name: record.name,
  235. }),
  236. };
  237. export const FilterAndUpdateDataSource = () => <FilterWithNewDataTable />;
  238. FilterAndUpdateDataSource.story = {
  239. name: 'filter and update dataSource',
  240. };
  241. export const SelectionTable = () => (
  242. <Table rowSelection={rowSelection} columns={columns} dataSource={data} />
  243. );
  244. SelectionTable.story = {
  245. name: 'selection table',
  246. };
  247. function ControlledSelectionTable() {
  248. const [selected, setSelected] = React.useState([]);
  249. const columns = [
  250. {
  251. title: 'Name',
  252. dataIndex: 'name',
  253. render: text => text,
  254. },
  255. {
  256. title: 'Age',
  257. dataIndex: 'age',
  258. },
  259. {
  260. title: 'Address',
  261. dataIndex: 'address',
  262. },
  263. ];
  264. const data = [
  265. {
  266. key: '1',
  267. name: 'John Brown',
  268. age: 32,
  269. address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
  270. },
  271. {
  272. key: '2',
  273. name: 'Jim Green',
  274. age: 42,
  275. address: 'London No. 1 Lake Park',
  276. },
  277. {
  278. key: '3',
  279. name: 'Joe Black',
  280. age: 32,
  281. address: 'Sidney No. 1 Lake Park',
  282. },
  283. {
  284. key: '4',
  285. name: 'Michael James',
  286. age: 99,
  287. address: 'Sidney No. 1 Lake Park',
  288. },
  289. ];
  290. const rowSelection = {
  291. onChange: (selectedRowKeys, selectedRows) => {
  292. setSelected(selectedRowKeys);
  293. },
  294. getCheckboxProps: record => ({
  295. disabled: selected.length === 2 && selected.findIndex(key => key === record.key) === -1, // Column configuration not to be checked
  296. name: record.name,
  297. }),
  298. selectedRowKeys: selected,
  299. };
  300. return (
  301. <Table columns={columns} dataSource={data} rowSelection={rowSelection} pagination={false} />
  302. );
  303. }
  304. export const _ControlledSelectionTable = () => <ControlledSelectionTable />;
  305. _ControlledSelectionTable.story = {
  306. name: 'controlled selection table',
  307. };
  308. _ControlledSelectionTable.parameters = {
  309. chromatic: { disableSnapshot: true },
  310. }
  311. // sortable table
  312. const sortColumns = [
  313. {
  314. title: 'Name',
  315. dataIndex: 'name',
  316. filters: [
  317. {
  318. text: 'XiaoMing',
  319. value: 'XiaoMing',
  320. },
  321. {
  322. text: 'ZhangSan',
  323. value: 'ZhangSan',
  324. },
  325. {
  326. text: 'SubMenu',
  327. value: 'SubMenu',
  328. children: [
  329. {
  330. text: 'Yellow',
  331. value: 'Yellow',
  332. },
  333. {
  334. text: 'Pink',
  335. value: 'Pink',
  336. },
  337. ],
  338. },
  339. ],
  340. onFilter: (value, record) => record.name.indexOf(value) === 0,
  341. sorter: (a, b) => a.name.length - b.name.length,
  342. sortDirections: ['descend'],
  343. sortOrder: 'descend',
  344. },
  345. {
  346. title: 'Age',
  347. dataIndex: 'age',
  348. defaultSortOrder: 'descend',
  349. sorter: (a, b) => a.age - b.age,
  350. },
  351. {
  352. title: 'Address',
  353. dataIndex: 'address',
  354. filters: [
  355. {
  356. text: 'BieJing',
  357. value: 'BeiJing',
  358. },
  359. {
  360. text: 'ShangHai',
  361. value: 'SHangHai',
  362. },
  363. ],
  364. filterMultiple: false,
  365. onFilter: (value, record) => record.address.indexOf(value) === 0,
  366. sorter: (a, b) => a.address.length - b.address.length,
  367. sortDirections: ['descend', 'ascend'],
  368. },
  369. ];
  370. const sortData = [
  371. {
  372. key: '1',
  373. name: 'ZhangSan',
  374. age: 50,
  375. address: 'BeiJing No.1 High School',
  376. },
  377. {
  378. key: '2',
  379. name: 'LiSi',
  380. age: 60,
  381. address: 'BeiJing No.2 High School',
  382. },
  383. {
  384. key: '3',
  385. name: 'WangWu',
  386. age: 20,
  387. address: 'BeiJing No.3 High School',
  388. },
  389. {
  390. key: '4',
  391. name: 'XiaoMing',
  392. age: 30,
  393. address: 'BeiJing No.5 High School',
  394. },
  395. ];
  396. export const SortTable = () => <Table columns={sortColumns} dataSource={sortData} />;
  397. SortTable.story = {
  398. name: 'sort table',
  399. };
  400. export const ControlledSortOrderTable = () => <ControlledSortOrder />;
  401. ControlledSortOrderTable.story = {
  402. name: 'controlled sortOrder table',
  403. };
  404. export const MiddleTable = () => <Table columns={columns} dataSource={data} size="middle" />;
  405. MiddleTable.story = {
  406. name: 'middle table',
  407. };
  408. export const SmallTable = () => <Table columns={columns} dataSource={data} size="small" />;
  409. SmallTable.story = {
  410. name: 'small table',
  411. };
  412. export const ExpandTable = () => <ExpandDemo />;
  413. ExpandTable.story = {
  414. name: 'expand table',
  415. };
  416. export const _ResizableColumns = () => <ResizableColumns />;
  417. _ResizableColumns.story = {
  418. name: 'resizable columns',
  419. };
  420. export const DragableTable = () => <DragableTableDemo />;
  421. DragableTable.story = {
  422. name: 'dragable table',
  423. };
  424. DragableTable.parameters = {
  425. chromatic: { disableSnapshot: true },
  426. }
  427. export const _FixedTable = () => <FixedTable />;
  428. _FixedTable.story = {
  429. name: 'fixed table',
  430. };
  431. _FixedTable.parameters = {
  432. chromatic: { disableSnapshot: true },
  433. }
  434. export const FixedJsxTable = () => <JSXFixedTable />;
  435. FixedJsxTable.story = {
  436. name: 'fixed jsx table',
  437. };
  438. export const JSXTitlesDemo = () => <JSXTitles />;
  439. JSXTitlesDemo.story = {
  440. name: 'jsx titles'
  441. };
  442. export const DynamicTable = () => (
  443. <div style={{ padding: 20 }}>
  444. <DynamicTableDemo />
  445. </div>
  446. );
  447. DynamicTable.story = {
  448. name: 'dynamic table',
  449. };
  450. export const _LinkedScroll = () => <LinkedScroll />;
  451. _LinkedScroll.story = {
  452. name: 'linked scroll',
  453. };
  454. export const _ModalTable = () => <ModalTable />;
  455. _ModalTable.story = {
  456. name: 'modal table',
  457. };
  458. export const _TabsTable = () => <TabsTable />;
  459. _TabsTable.story = {
  460. name: 'tabs table',
  461. };
  462. export const _EventTable = () => <EventTable />;
  463. _EventTable.story = {
  464. name: 'event table',
  465. };
  466. export const _FnTable = () => <FnTable />;
  467. _FnTable.story = {
  468. name: 'fn table',
  469. };
  470. export const _DynamicFilters = () => <DynamicFilters />;
  471. _DynamicFilters.story = {
  472. name: 'dynamic filters',
  473. };
  474. export const _ResizableTable = () => <ResizableTable />;
  475. _ResizableTable.story = {
  476. name: 'resizable table',
  477. };
  478. export const WithPagination = () => <PaginationDemo />;
  479. WithPagination.story = {
  480. name: 'with pagination',
  481. };
  482. export const SelectedRows = () => <SelectedRowsDemo />;
  483. SelectedRows.story = {
  484. name: 'selected rows',
  485. };
  486. export const _ChildrenData = () => <ChildrenData />;
  487. _ChildrenData.story = {
  488. name: 'children data',
  489. };
  490. export const ChildrenDataSelectedRows = () => <ChildrenDataSelected />;
  491. ChildrenDataSelectedRows.story = {
  492. name: 'children data selected rows',
  493. };
  494. export const _ExpandAllRows = () => <ExpandAllRows />;
  495. _ExpandAllRows.story = {
  496. name: 'expandAllRows',
  497. };
  498. export const _ExpandAllGroupRows = () => <ExpandAllGroupRows />;
  499. _ExpandAllGroupRows.story = {
  500. name: 'expandAllGroupRows',
  501. };
  502. export const _ExpandRowByClick = () => <ExpandRowByClick />;
  503. _ExpandRowByClick.story = {
  504. name: 'expandRowByClick',
  505. };
  506. export const RowSelectionBoolean = () => <Table columns={columns} dataSource={data} rowSelection />;
  507. RowSelectionBoolean.story = {
  508. name: 'rowSelection boolean',
  509. };
  510. export const _FixAllColumnsWithoutWidth = () => <FixAllColumnsWithoutWidth />;
  511. _FixAllColumnsWithoutWidth.story = {
  512. name: 'fix all columns without width',
  513. };
  514. export const JSXColumnPropColumnDemo = () => <JSXColumnPropColumn />;
  515. export const FixedExpandedRowsDemo = () => <FixedExpandedRows />;
  516. FixedExpandedRowsDemo.parameters = {
  517. chromatic: { disableSnapshot: true },
  518. }
  519. export const CustomFilterDropdownItemDemo = () => <CustomFilterDropdownItem />;
  520. export const Virtualized = () => <VirtualizedDemo />;
  521. export const VirtualizedNotFixedDemo = () => <VirtualizedNotFixed />;
  522. export const InfiniteScrollDemo = () => <InfiniteScroll />;
  523. export const VirtualTableOnCellDemo = () => <VirtualTableOnCell />;
  524. export const ControlledSelectionDemo = () => <ControlledSelection />;
  525. ControlledSelectionDemo.parameters = {
  526. chromatic: { disableSnapshot: true },
  527. }
  528. export const PerfComplexRenderDemo = () => <PerfComplexRender />;
  529. PerfComplexRenderDemo.parameters = {
  530. chromatic: { disableSnapshot: true },
  531. }
  532. export const PerfContextDemo = () => <PerfContext />;
  533. export const PerfOnRowDemo = () => <PerfOnRow />;
  534. PerfOnRowDemo.parameters = {
  535. chromatic: { disableSnapshot: true },
  536. }
  537. export const PerfResizableSelectionDemo = () => <PerfResizableSelection />;
  538. PerfResizableSelectionDemo.parameters = {
  539. chromatic: { disableSnapshot: true },
  540. }
  541. export const PerfVirtualizedDemo = () => <PerfVirtualized />;
  542. export const PerfRenderDemo = () => <PerfRender />;
  543. PerfRenderDemo.parameters = {
  544. chromatic: { disableSnapshot: true },
  545. }
  546. export const RenderPaginationDemo = () => <RenderPagination />;
  547. export const HugeDataDemo = ()=><HugeData/>
  548. HugeDataDemo.parameters = {
  549. chromatic: { disableSnapshot: true },
  550. };
  551. export const _RowSelectionRenderCell = () => <RowSelectionRenderCell />;
  552. _RowSelectionRenderCell.story = {
  553. name: 'RowSelection RenderCell',
  554. };