Skip to content

Commit

Permalink
perf: rename some function
Browse files Browse the repository at this point in the history
  • Loading branch information
hemengke1997 committed Dec 6, 2021
1 parent 2c79114 commit 2c80499
Show file tree
Hide file tree
Showing 9 changed files with 1,823 additions and 3,569 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ yarn add use-antd-resizable-header
- **默认拖动颜色为`#000`,可通过`global`或设置 css 变量`--atrh-color`设置颜色**
- **至少一列不能拖动(width 不设置即可),[请保持最后至少一列的自适应](https://ant-design.gitee.io/components/table-cn/#components-table-demo-fixed-columns)**
- **若 column 未传入`dataIndex`,请传入一个唯一的`key`,否则按照将按照 column 的序号 index 计算唯一 key**
- **remenber import style**

## Example

Expand Down
317 changes: 160 additions & 157 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Table, TableColumnType } from 'antd';
import { Table } from 'antd';
import ProTable, { ProColumns } from '@ant-design/pro-table';
import './App.css';
import useATRH from 'use-antd-resizable-header';
Expand All @@ -15,165 +15,168 @@ for (let i = 0; i < 100; i++) {
address: `London Park no. ${i}`,
});
}
const columns = [
{
title: 'Name',
width: 100,
dataIndex: 'name',
key: 'name',
fixed: 'left',
},
{
title: 'Age',
width: 100,
dataIndex: 'age',
key: 'age',
},
{
title: 'Column 1',
dataIndex: 'address',
key: '1',
width: 150,
},
{
title: 'Column 2',
dataIndex: 'address',
key: '2',
width: 150,
},
{
title: 'Column 3',
dataIndex: 'address',
key: '3',
width: 150,
},
{
title: 'Column 4',
dataIndex: 'address',
key: '4',
width: 150,
},
{
title: 'Column 5',
dataIndex: 'address',
key: '5',
width: 150,
},
{
title: 'Column 6',
dataIndex: 'address',
key: '6',
width: 150,
},
{
title: 'Column 7777777777777',
dataIndex: 'address',
key: '7',
width: 150,
},
{
title: 'Column 8',
dataIndex: 'address',
key: '8',
width: 150,
},
{
title: 'Column 9',
dataIndex: 'address',
key: '9',
width: 150,
},
{ title: 'Column 10', dataIndex: 'address', key: '10' },
{
title: 'Action',
key: 'operation',
fixed: 'right',
width: 100,
render: (record) => {
return <span>{record.address}</span>;
},
},
];

const proColumns: ProColumns<any>[] = [
{
title: 'Name',
width: 100,
dataIndex: 'name',
key: 'name',
fixed: 'left',
},
{
title: 'Age',
width: 100,
dataIndex: 'age',
key: 'age',
},
{
title: 'Column 1',
dataIndex: 'address',
key: '1',
width: 150,
},
{
title: 'Column 2',
dataIndex: 'address',
key: '2',
width: 150,
},
{
title: 'Column 3',
dataIndex: 'address',
key: '3',
width: 150,
},
{
title: 'Column 4',
dataIndex: 'address',
key: '4',
width: 150,
},
{
title: 'Column 5',
dataIndex: 'address',
key: '5',
width: 150,
},
{
title: 'Column 6',
dataIndex: 'address',
key: '6',
width: 150,
},
{
title: 'Column 7777777777777',
dataIndex: 'address',
key: '7',
width: 150,
},
{
title: 'Column 8',
dataIndex: 'address',
key: '8',
width: 150,
},
{
title: 'Column 9',
dataIndex: 'address',
key: '9',
width: 150,
},
{ title: 'Column 10', dataIndex: 'address', key: '10' },
{
title: 'Action',
key: 'operation',
fixed: 'right',
width: 100,
render: () => <a>action</a>,
},
];

function App() {

const columns = [
{
title: 'Name',
width: 100,
dataIndex: 'name',
key: 'name',
fixed: 'left',
},
{
title: 'Age',
width: 100,
dataIndex: 'age',
key: 'age',
},
{
title: 'Column 1',
dataIndex: 'address',
key: '1',
width: 150,
},
{
title: 'Column 2',
dataIndex: 'address',
key: '2',
width: 150,
},
{
title: 'Column 3',
dataIndex: 'address',
key: '3',
width: 150,
},
{
title: 'Column 4',
dataIndex: 'address',
key: '4',
width: 150,
},
{
title: 'Column 5',
dataIndex: 'address',
key: '5',
width: 150,
},
{
title: 'Column 6',
dataIndex: 'address',
key: '6',
width: 150,
},
{
title: 'Column 7777777777777',
dataIndex: 'address',
key: '7',
width: 150,
},
{
title: 'Column 8',
dataIndex: 'address',
key: '8',
width: 150,
},
{
title: 'Column 9',
dataIndex: 'address',
key: '9',
width: 150,
},
{ title: 'Column 10', dataIndex: 'address', key: '10' },
{
title: 'Action',
key: 'operation',
fixed: 'right',
width: 100,
render: (record: any) => {
return <span>{record?.address || ''}</span>;
},
},
];

const proColumns: ProColumns<any>[] = [
{
title: 'Name',
width: 100,
dataIndex: 'name',
key: 'name',
fixed: 'left',
},
{
title: 'Age',
width: 100,
dataIndex: 'age',
key: 'age',
},
{
title: 'Column 1',
dataIndex: 'address',
key: '1',
width: 150,
},
{
title: 'Column 2',
dataIndex: 'address',
key: '2',
width: 150,
},
{
title: 'Column 3',
dataIndex: 'address',
key: '3',
width: 150,
},
{
title: 'Column 4',
dataIndex: 'address',
key: '4',
width: 150,
},
{
title: 'Column 5',
dataIndex: 'address',
key: '5',
width: 150,
},
{
title: 'Column 6',
dataIndex: 'address',
key: '6',
width: 150,
},
{
title: 'Column 7777777777777',
dataIndex: 'address',
key: '7',
width: 150,
},
{
title: 'Column 8',
dataIndex: 'address',
key: '8',
width: 150,
},
{
title: 'Column 9',
dataIndex: 'address',
key: '9',
width: 150,
},
{ title: 'Column 10', dataIndex: 'address', key: '10' },
{
title: 'Action',
key: 'operation',
fixed: 'right',
width: 100,
render: () => <a>action</a>,
},
];

const { components, resizableColumns, tableWidth } = useATRH({columns});

const {
Expand Down
3 changes: 1 addition & 2 deletions example/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import Test from './Test';

ReactDOM.render(
<React.StrictMode>
<App />
<Test />
{/* <Test /> */}
</React.StrictMode>,
document.getElementById('root'),
);
20 changes: 20 additions & 0 deletions example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ lodash-es@^4.17.15:
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=

lodash.isempty@4.4.0:
version "4.4.0"
resolved "https://registry.npmjs.org/lodash.isempty/-/lodash.isempty-4.4.0.tgz#6f86cbedd8be4ec987be9aaf33c9684db1b31e7e"
integrity sha1-b4bL7di+TsmHvpqvM8loTbGzHn4=

lodash.isequalwith@^4.4.0:
version "4.4.0"
resolved "https://registry.npmjs.org/lodash.isequalwith/-/lodash.isequalwith-4.4.0.tgz#266726ddd528f854f21f4ea98a065606e0fbc6b0"
integrity sha1-Jmcm3dUo+FTyH06pigZWBuD7xrA=

lodash.isfunction@^3.0.9:
version "3.0.9"
resolved "https://registry.npmjs.org/lodash.isfunction/-/lodash.isfunction-3.0.9.tgz#06de25df4db327ac931981d1bdb067e5af68d051"
integrity sha512-AirXNj15uRIMMPihnkInB4i3NHeb4iBtNg9WRWuK2o31S+ePwwNmDPaTL3o7dTJ+VXNZim7rFs4rxN4YU1oUJw==

lodash.merge@^4.6.2:
version "4.6.2"
resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a"
Expand Down
Loading

0 comments on commit 2c80499

Please sign in to comment.