@gmfe/table-x 2.14.17 → 2.14.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -13
- package/package.json +4 -4
- package/src/base/index.js +142 -142
- package/src/base/td.js +56 -56
- package/src/base/th.js +48 -48
- package/src/base/thead.js +26 -26
- package/src/base/tr.js +53 -53
- package/src/base/virtualized.js +219 -219
- package/src/hoc/diy_table_x/components/diy_table_x_modal.js +135 -135
- package/src/hoc/diy_table_x/components/modal_list.js +78 -78
- package/src/hoc/diy_table_x/components/modal_selector.js +56 -56
- package/src/hoc/diy_table_x/index.js +196 -196
- package/src/hoc/edit_table_x.js +20 -20
- package/src/hoc/expand_table_x/index.js +140 -140
- package/src/hoc/expand_table_x/util.js +27 -27
- package/src/hoc/fixed_columns_table_x.js +29 -29
- package/src/hoc/select_table_x/cell.js +51 -51
- package/src/hoc/select_table_x/header.js +28 -28
- package/src/hoc/select_table_x/index.js +139 -139
- package/src/hoc/select_table_x/util.js +10 -10
- package/src/hoc/sortable_table_x.js +52 -52
- package/src/hoc/sub_table_x.js +44 -44
- package/src/index.js +53 -53
- package/src/index.less +515 -515
- package/src/stories/table_x.stories.js +324 -324
- package/src/stories/table_x_hoc.stories.js +427 -427
- package/src/stories/table_x_hoc_select_expand.stories.js +256 -256
- package/src/util/batch_action_bar.js +124 -124
- package/src/util/edit.js +83 -83
- package/src/util/index.js +191 -191
- package/src/util/operation.js +249 -249
- package/src/util/sort_header.js +49 -49
- package/src/variables.less +28 -28
- package/svg/business.svg +20 -20
- package/svg/check-detail.svg +18 -18
- package/svg/closeup.svg +20 -20
- package/svg/delete.svg +10 -10
- package/svg/edit-pen.svg +17 -17
- package/svg/empty.svg +27 -27
- package/svg/expand.svg +21 -21
- package/svg/pen.svg +12 -12
- package/svg/recover.svg +33 -33
- package/svg/remove.svg +1 -1
- package/svg/setting.svg +17 -17
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
## tableX 踩的坑,阅读后改代码更自信
|
|
2
|
-
|
|
3
|
-
- 注意不要随意升级版本,目前使用 7.0.0-rc.11
|
|
4
|
-
- 7.0.0-rc.11 天然不支持 column.show, 所以自行实现了 column.show 的支持.[issue](https://github.com/tannerlinsley/react-table/issues/1665)
|
|
5
|
-
- defaultColumn 的值不要轻易改动,具体看代码。目前实现了 minWidth,width,maxWidth 逻辑与 v6 一致,且需语义一致。
|
|
6
|
-
- 使用 useResizeColumns 后,无法兼容到 v6 的 minWidth,width,maxWidth 的实现,所以去掉了 useResizeColumns
|
|
7
|
-
- 斑马线,不能用 css 的 `:even` 和 `:odd` 实现。因为在使用虚拟列表的时候有坑。
|
|
8
|
-
- 使用.gm-table-x-td 定义 background 是有原因的,比如 使用 fixedColumnHOC 时候的背景穿透问题
|
|
9
|
-
- 虚拟列表的实现是 copy 了一份 TableX,请保证一致
|
|
10
|
-
- 改动需要考虑 keyboard 那边
|
|
11
|
-
- keyboard 测试 向上下左右是否有问题,特别是不在显示区域的是否可以滚动到显示区域
|
|
12
|
-
- keyboard 新增一行的性能,行数很大的时候的性能
|
|
13
|
-
- keyboard 的 input 不会因为新增而换掉 dom。即 控制台打出该 dom,在新增后 hover 到控制台的 dom 还能找到
|
|
1
|
+
## tableX 踩的坑,阅读后改代码更自信
|
|
2
|
+
|
|
3
|
+
- 注意不要随意升级版本,目前使用 7.0.0-rc.11
|
|
4
|
+
- 7.0.0-rc.11 天然不支持 column.show, 所以自行实现了 column.show 的支持.[issue](https://github.com/tannerlinsley/react-table/issues/1665)
|
|
5
|
+
- defaultColumn 的值不要轻易改动,具体看代码。目前实现了 minWidth,width,maxWidth 逻辑与 v6 一致,且需语义一致。
|
|
6
|
+
- 使用 useResizeColumns 后,无法兼容到 v6 的 minWidth,width,maxWidth 的实现,所以去掉了 useResizeColumns
|
|
7
|
+
- 斑马线,不能用 css 的 `:even` 和 `:odd` 实现。因为在使用虚拟列表的时候有坑。
|
|
8
|
+
- 使用.gm-table-x-td 定义 background 是有原因的,比如 使用 fixedColumnHOC 时候的背景穿透问题
|
|
9
|
+
- 虚拟列表的实现是 copy 了一份 TableX,请保证一致
|
|
10
|
+
- 改动需要考虑 keyboard 那边
|
|
11
|
+
- keyboard 测试 向上下左右是否有问题,特别是不在显示区域的是否可以滚动到显示区域
|
|
12
|
+
- keyboard 新增一行的性能,行数很大的时候的性能
|
|
13
|
+
- keyboard 的 input 不会因为新增而换掉 dom。即 控制台打出该 dom,在新增后 hover 到控制台的 dom 还能找到
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gmfe/table-x",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gmfe#readme",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@gm-common/tool": "^1.0.0",
|
|
30
|
-
"@gmfe/locales": "^2.14.
|
|
31
|
-
"@gmfe/react": "^2.14.
|
|
30
|
+
"@gmfe/locales": "^2.14.20",
|
|
31
|
+
"@gmfe/react": "^2.14.20",
|
|
32
32
|
"classnames": "^2.2.5",
|
|
33
33
|
"lodash": "^4.17.14",
|
|
34
34
|
"prop-types": "^15.7.2",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"react-window": "^1.8.5",
|
|
37
37
|
"sortablejs": "^1.10.1"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "ffd6acec5aca29adfa9e078ea8a0bcbec7a9cd74"
|
|
40
40
|
}
|
package/src/base/index.js
CHANGED
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import PropTypes from 'prop-types'
|
|
3
|
-
import { useTable } from 'react-table'
|
|
4
|
-
import { Empty, Loading, afterScroll, __DEFAULT_COLUMN } from '../util'
|
|
5
|
-
import classNames from 'classnames'
|
|
6
|
-
import _ from 'lodash'
|
|
7
|
-
import THead from './thead'
|
|
8
|
-
import Tr from './tr'
|
|
9
|
-
|
|
10
|
-
// 给定初始值,交由getColumnStyle控制。width逻辑保持跟react-table(v6)的用法一致。
|
|
11
|
-
const defaultColumn = __DEFAULT_COLUMN
|
|
12
|
-
|
|
13
|
-
const TableX = ({
|
|
14
|
-
columns,
|
|
15
|
-
data,
|
|
16
|
-
loading,
|
|
17
|
-
SubComponent,
|
|
18
|
-
keyField,
|
|
19
|
-
className,
|
|
20
|
-
tiled,
|
|
21
|
-
onScroll,
|
|
22
|
-
isTrDisable,
|
|
23
|
-
isTrHighlight,
|
|
24
|
-
...rest
|
|
25
|
-
}) => {
|
|
26
|
-
// diy fixed(最新rc12不支持column.show,自己实现)
|
|
27
|
-
columns = React.useMemo(() => columns.filter(c => c.show !== false), [
|
|
28
|
-
columns
|
|
29
|
-
])
|
|
30
|
-
|
|
31
|
-
const {
|
|
32
|
-
getTableProps,
|
|
33
|
-
headerGroups,
|
|
34
|
-
getTableBodyProps,
|
|
35
|
-
rows,
|
|
36
|
-
prepareRow
|
|
37
|
-
} = useTable({
|
|
38
|
-
columns,
|
|
39
|
-
data,
|
|
40
|
-
defaultColumn
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
let totalWidth = 0
|
|
44
|
-
if (rows[0] && rows[0].cells.length > 0) {
|
|
45
|
-
prepareRow(rows[0])
|
|
46
|
-
const last = rows[0].cells[rows[0].cells.length - 1].column
|
|
47
|
-
totalWidth = last.totalLeft + last.totalWidth
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const gtp = getTableProps()
|
|
51
|
-
const tableProps = {
|
|
52
|
-
...gtp,
|
|
53
|
-
style: { minWidth: totalWidth + 'px' },
|
|
54
|
-
className: classNames('gm-table-x-table', gtp.className)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const gtbp = getTableBodyProps()
|
|
58
|
-
const tableBodyProps = {
|
|
59
|
-
...gtbp,
|
|
60
|
-
className: 'gm-table-x-tbody'
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const handleScroll = e => {
|
|
64
|
-
onScroll && onScroll(e)
|
|
65
|
-
afterScroll()
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// eslint-disable-next-line
|
|
69
|
-
const RenderRow = ({ index, style }) => {
|
|
70
|
-
const row = rows[index]
|
|
71
|
-
prepareRow(row)
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<Tr
|
|
75
|
-
key={row.index}
|
|
76
|
-
row={row}
|
|
77
|
-
SubComponent={SubComponent}
|
|
78
|
-
keyField={keyField}
|
|
79
|
-
style={style}
|
|
80
|
-
totalWidth={totalWidth}
|
|
81
|
-
isTrDisable={isTrDisable}
|
|
82
|
-
isTrHighlight={isTrHighlight}
|
|
83
|
-
/>
|
|
84
|
-
)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<div
|
|
89
|
-
{...rest}
|
|
90
|
-
className={classNames(
|
|
91
|
-
'gm-table-x',
|
|
92
|
-
{
|
|
93
|
-
'gm-table-x-empty': data.length === 0,
|
|
94
|
-
'gm-table-x-tiled': tiled
|
|
95
|
-
},
|
|
96
|
-
className
|
|
97
|
-
)}
|
|
98
|
-
onScroll={handleScroll}
|
|
99
|
-
>
|
|
100
|
-
<table {...tableProps}>
|
|
101
|
-
<THead headerGroups={headerGroups} totalWidth={totalWidth} />
|
|
102
|
-
<tbody {...tableBodyProps}>
|
|
103
|
-
{_.map(rows, row =>
|
|
104
|
-
RenderRow({
|
|
105
|
-
index: row.index,
|
|
106
|
-
style: {}
|
|
107
|
-
})
|
|
108
|
-
)}
|
|
109
|
-
</tbody>
|
|
110
|
-
</table>
|
|
111
|
-
{loading && <Loading />}
|
|
112
|
-
{!loading && data.length === 0 && <Empty />}
|
|
113
|
-
</div>
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
TableX.propTypes = {
|
|
118
|
-
columns: PropTypes.array.isRequired,
|
|
119
|
-
data: PropTypes.array.isRequired,
|
|
120
|
-
loading: PropTypes.bool,
|
|
121
|
-
SubComponent: PropTypes.func,
|
|
122
|
-
/** 由其他 hoc 传下来 */
|
|
123
|
-
keyField: PropTypes.string,
|
|
124
|
-
/** table是否平铺 */
|
|
125
|
-
tiled: PropTypes.bool,
|
|
126
|
-
/** 当前行是否disable */
|
|
127
|
-
isTrDisable: PropTypes.func,
|
|
128
|
-
/** 当前行是否高亮 */
|
|
129
|
-
isTrHighlight: PropTypes.func,
|
|
130
|
-
onScroll: PropTypes.func,
|
|
131
|
-
className: PropTypes.string,
|
|
132
|
-
style: PropTypes.object
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
TableX.defaultProps = {
|
|
136
|
-
keyField: 'value',
|
|
137
|
-
tiled: false,
|
|
138
|
-
isTrDisable: () => false,
|
|
139
|
-
isTrHighlight: () => false
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export default TableX
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { useTable } from 'react-table'
|
|
4
|
+
import { Empty, Loading, afterScroll, __DEFAULT_COLUMN } from '../util'
|
|
5
|
+
import classNames from 'classnames'
|
|
6
|
+
import _ from 'lodash'
|
|
7
|
+
import THead from './thead'
|
|
8
|
+
import Tr from './tr'
|
|
9
|
+
|
|
10
|
+
// 给定初始值,交由getColumnStyle控制。width逻辑保持跟react-table(v6)的用法一致。
|
|
11
|
+
const defaultColumn = __DEFAULT_COLUMN
|
|
12
|
+
|
|
13
|
+
const TableX = ({
|
|
14
|
+
columns,
|
|
15
|
+
data,
|
|
16
|
+
loading,
|
|
17
|
+
SubComponent,
|
|
18
|
+
keyField,
|
|
19
|
+
className,
|
|
20
|
+
tiled,
|
|
21
|
+
onScroll,
|
|
22
|
+
isTrDisable,
|
|
23
|
+
isTrHighlight,
|
|
24
|
+
...rest
|
|
25
|
+
}) => {
|
|
26
|
+
// diy fixed(最新rc12不支持column.show,自己实现)
|
|
27
|
+
columns = React.useMemo(() => columns.filter(c => c.show !== false), [
|
|
28
|
+
columns
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
getTableProps,
|
|
33
|
+
headerGroups,
|
|
34
|
+
getTableBodyProps,
|
|
35
|
+
rows,
|
|
36
|
+
prepareRow
|
|
37
|
+
} = useTable({
|
|
38
|
+
columns,
|
|
39
|
+
data,
|
|
40
|
+
defaultColumn
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
let totalWidth = 0
|
|
44
|
+
if (rows[0] && rows[0].cells.length > 0) {
|
|
45
|
+
prepareRow(rows[0])
|
|
46
|
+
const last = rows[0].cells[rows[0].cells.length - 1].column
|
|
47
|
+
totalWidth = last.totalLeft + last.totalWidth
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const gtp = getTableProps()
|
|
51
|
+
const tableProps = {
|
|
52
|
+
...gtp,
|
|
53
|
+
style: { minWidth: totalWidth + 'px' },
|
|
54
|
+
className: classNames('gm-table-x-table', gtp.className)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const gtbp = getTableBodyProps()
|
|
58
|
+
const tableBodyProps = {
|
|
59
|
+
...gtbp,
|
|
60
|
+
className: 'gm-table-x-tbody'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const handleScroll = e => {
|
|
64
|
+
onScroll && onScroll(e)
|
|
65
|
+
afterScroll()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line
|
|
69
|
+
const RenderRow = ({ index, style }) => {
|
|
70
|
+
const row = rows[index]
|
|
71
|
+
prepareRow(row)
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<Tr
|
|
75
|
+
key={row.index}
|
|
76
|
+
row={row}
|
|
77
|
+
SubComponent={SubComponent}
|
|
78
|
+
keyField={keyField}
|
|
79
|
+
style={style}
|
|
80
|
+
totalWidth={totalWidth}
|
|
81
|
+
isTrDisable={isTrDisable}
|
|
82
|
+
isTrHighlight={isTrHighlight}
|
|
83
|
+
/>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div
|
|
89
|
+
{...rest}
|
|
90
|
+
className={classNames(
|
|
91
|
+
'gm-table-x',
|
|
92
|
+
{
|
|
93
|
+
'gm-table-x-empty': data.length === 0,
|
|
94
|
+
'gm-table-x-tiled': tiled
|
|
95
|
+
},
|
|
96
|
+
className
|
|
97
|
+
)}
|
|
98
|
+
onScroll={handleScroll}
|
|
99
|
+
>
|
|
100
|
+
<table {...tableProps}>
|
|
101
|
+
<THead headerGroups={headerGroups} totalWidth={totalWidth} />
|
|
102
|
+
<tbody {...tableBodyProps}>
|
|
103
|
+
{_.map(rows, row =>
|
|
104
|
+
RenderRow({
|
|
105
|
+
index: row.index,
|
|
106
|
+
style: {}
|
|
107
|
+
})
|
|
108
|
+
)}
|
|
109
|
+
</tbody>
|
|
110
|
+
</table>
|
|
111
|
+
{loading && <Loading />}
|
|
112
|
+
{!loading && data.length === 0 && <Empty />}
|
|
113
|
+
</div>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
TableX.propTypes = {
|
|
118
|
+
columns: PropTypes.array.isRequired,
|
|
119
|
+
data: PropTypes.array.isRequired,
|
|
120
|
+
loading: PropTypes.bool,
|
|
121
|
+
SubComponent: PropTypes.func,
|
|
122
|
+
/** 由其他 hoc 传下来 */
|
|
123
|
+
keyField: PropTypes.string,
|
|
124
|
+
/** table是否平铺 */
|
|
125
|
+
tiled: PropTypes.bool,
|
|
126
|
+
/** 当前行是否disable */
|
|
127
|
+
isTrDisable: PropTypes.func,
|
|
128
|
+
/** 当前行是否高亮 */
|
|
129
|
+
isTrHighlight: PropTypes.func,
|
|
130
|
+
onScroll: PropTypes.func,
|
|
131
|
+
className: PropTypes.string,
|
|
132
|
+
style: PropTypes.object
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
TableX.defaultProps = {
|
|
136
|
+
keyField: 'value',
|
|
137
|
+
tiled: false,
|
|
138
|
+
isTrDisable: () => false,
|
|
139
|
+
isTrHighlight: () => false
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export default TableX
|
package/src/base/td.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import classNames from 'classnames'
|
|
2
|
-
import { getColumnStyle } from '../util'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
// cell.render('Cell') 是一个react组件,如果这个组件return undefined,那就就会报错
|
|
7
|
-
// 这里是为了兼容 cell.render('Cell') 返回undefined的情况
|
|
8
|
-
class TdCatchErr extends React.Component {
|
|
9
|
-
componentDidCatch(error, errorInfo) {
|
|
10
|
-
console.warn(error)
|
|
11
|
-
console.warn(errorInfo.componentStack)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
render() {
|
|
15
|
-
return this.props.children
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const Td = ({ cell, totalWidth }) => {
|
|
20
|
-
const cp = cell.getCellProps()
|
|
21
|
-
const { tdClassName } = cell.column
|
|
22
|
-
const tdProps = {
|
|
23
|
-
...cp,
|
|
24
|
-
className: classNames('gm-table-x-td', tdClassName, {
|
|
25
|
-
'gm-table-x-fixed-left': cell.column.fixed === 'left',
|
|
26
|
-
'gm-table-x-fixed-right': cell.column.fixed === 'right'
|
|
27
|
-
}),
|
|
28
|
-
style: {
|
|
29
|
-
...cp.style,
|
|
30
|
-
...getColumnStyle(cell.column)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (cell.column.fixed === 'left') {
|
|
35
|
-
// 用到 fixed,可以利用 totalLeft
|
|
36
|
-
tdProps.style.left = cell.column.totalLeft
|
|
37
|
-
} else if (cell.column.fixed === 'right') {
|
|
38
|
-
tdProps.style.right =
|
|
39
|
-
totalWidth - cell.column.totalLeft - cell.column.totalWidth
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<td {...tdProps}>
|
|
44
|
-
<TdCatchErr>{cell.render('Cell')}</TdCatchErr>
|
|
45
|
-
</td>
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
Td.whyDidYouRender = true
|
|
50
|
-
|
|
51
|
-
Td.propTypes = {
|
|
52
|
-
cell: PropTypes.object.isRequired,
|
|
53
|
-
totalWidth: PropTypes.number.isRequired
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default React.memo(Td)
|
|
1
|
+
import classNames from 'classnames'
|
|
2
|
+
import { getColumnStyle } from '../util'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
// cell.render('Cell') 是一个react组件,如果这个组件return undefined,那就就会报错
|
|
7
|
+
// 这里是为了兼容 cell.render('Cell') 返回undefined的情况
|
|
8
|
+
class TdCatchErr extends React.Component {
|
|
9
|
+
componentDidCatch(error, errorInfo) {
|
|
10
|
+
console.warn(error)
|
|
11
|
+
console.warn(errorInfo.componentStack)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
render() {
|
|
15
|
+
return this.props.children
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const Td = ({ cell, totalWidth }) => {
|
|
20
|
+
const cp = cell.getCellProps()
|
|
21
|
+
const { tdClassName } = cell.column
|
|
22
|
+
const tdProps = {
|
|
23
|
+
...cp,
|
|
24
|
+
className: classNames('gm-table-x-td', tdClassName, {
|
|
25
|
+
'gm-table-x-fixed-left': cell.column.fixed === 'left',
|
|
26
|
+
'gm-table-x-fixed-right': cell.column.fixed === 'right'
|
|
27
|
+
}),
|
|
28
|
+
style: {
|
|
29
|
+
...cp.style,
|
|
30
|
+
...getColumnStyle(cell.column)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (cell.column.fixed === 'left') {
|
|
35
|
+
// 用到 fixed,可以利用 totalLeft
|
|
36
|
+
tdProps.style.left = cell.column.totalLeft
|
|
37
|
+
} else if (cell.column.fixed === 'right') {
|
|
38
|
+
tdProps.style.right =
|
|
39
|
+
totalWidth - cell.column.totalLeft - cell.column.totalWidth
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<td {...tdProps}>
|
|
44
|
+
<TdCatchErr>{cell.render('Cell')}</TdCatchErr>
|
|
45
|
+
</td>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Td.whyDidYouRender = true
|
|
50
|
+
|
|
51
|
+
Td.propTypes = {
|
|
52
|
+
cell: PropTypes.object.isRequired,
|
|
53
|
+
totalWidth: PropTypes.number.isRequired
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default React.memo(Td)
|
package/src/base/th.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import classNames from 'classnames'
|
|
2
|
-
import { getColumnStyle, SortHeader } from '../util'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
|
|
6
|
-
const Th = ({ column, totalWidth }) => {
|
|
7
|
-
const hp = column.getHeaderProps()
|
|
8
|
-
const { thClassName, style } = column
|
|
9
|
-
const thProps = {
|
|
10
|
-
...hp,
|
|
11
|
-
className: classNames('gm-table-x-th', hp.className, thClassName, {
|
|
12
|
-
'gm-table-x-fixed-left': column.fixed === 'left',
|
|
13
|
-
'gm-table-x-fixed-right': column.fixed === 'right'
|
|
14
|
-
}),
|
|
15
|
-
style: {
|
|
16
|
-
...hp.style,
|
|
17
|
-
...style,
|
|
18
|
-
...getColumnStyle(column)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (column.fixed === 'left') {
|
|
23
|
-
thProps.style.left = column.totalLeft
|
|
24
|
-
} else if (column.fixed === 'right') {
|
|
25
|
-
thProps.style.right = totalWidth - column.totalLeft - column.totalWidth
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<th {...thProps}>
|
|
30
|
-
{column.render('Header')}
|
|
31
|
-
{column.canSort && (
|
|
32
|
-
<SortHeader
|
|
33
|
-
{...column.getSortByToggleProps()}
|
|
34
|
-
type={column.isSorted ? (column.isSortedDesc ? 'desc' : 'asc') : null}
|
|
35
|
-
/>
|
|
36
|
-
)}
|
|
37
|
-
</th>
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
Th.whyDidYouRender = true
|
|
42
|
-
|
|
43
|
-
Th.propTypes = {
|
|
44
|
-
column: PropTypes.object.isRequired,
|
|
45
|
-
totalWidth: PropTypes.number.isRequired
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default React.memo(Th)
|
|
1
|
+
import classNames from 'classnames'
|
|
2
|
+
import { getColumnStyle, SortHeader } from '../util'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
const Th = ({ column, totalWidth }) => {
|
|
7
|
+
const hp = column.getHeaderProps()
|
|
8
|
+
const { thClassName, style } = column
|
|
9
|
+
const thProps = {
|
|
10
|
+
...hp,
|
|
11
|
+
className: classNames('gm-table-x-th', hp.className, thClassName, {
|
|
12
|
+
'gm-table-x-fixed-left': column.fixed === 'left',
|
|
13
|
+
'gm-table-x-fixed-right': column.fixed === 'right'
|
|
14
|
+
}),
|
|
15
|
+
style: {
|
|
16
|
+
...hp.style,
|
|
17
|
+
...style,
|
|
18
|
+
...getColumnStyle(column)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (column.fixed === 'left') {
|
|
23
|
+
thProps.style.left = column.totalLeft
|
|
24
|
+
} else if (column.fixed === 'right') {
|
|
25
|
+
thProps.style.right = totalWidth - column.totalLeft - column.totalWidth
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<th {...thProps}>
|
|
30
|
+
{column.render('Header')}
|
|
31
|
+
{column.canSort && (
|
|
32
|
+
<SortHeader
|
|
33
|
+
{...column.getSortByToggleProps()}
|
|
34
|
+
type={column.isSorted ? (column.isSortedDesc ? 'desc' : 'asc') : null}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
</th>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Th.whyDidYouRender = true
|
|
42
|
+
|
|
43
|
+
Th.propTypes = {
|
|
44
|
+
column: PropTypes.object.isRequired,
|
|
45
|
+
totalWidth: PropTypes.number.isRequired
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default React.memo(Th)
|
package/src/base/thead.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import PropTypes from 'prop-types'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
import Th from './th'
|
|
4
|
-
|
|
5
|
-
const THead = ({ headerGroups, totalWidth }) => {
|
|
6
|
-
return (
|
|
7
|
-
<thead className='gm-table-x-thead'>
|
|
8
|
-
{headerGroups.map((headerGroup, i) => (
|
|
9
|
-
<tr key={i} className='gm-table-x-tr'>
|
|
10
|
-
{headerGroup.headers.map((column, i) => (
|
|
11
|
-
<Th key={i} column={column} totalWidth={totalWidth} />
|
|
12
|
-
))}
|
|
13
|
-
</tr>
|
|
14
|
-
))}
|
|
15
|
-
</thead>
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
THead.whyDidYouRender = true
|
|
20
|
-
|
|
21
|
-
THead.propTypes = {
|
|
22
|
-
headerGroups: PropTypes.array.isRequired,
|
|
23
|
-
totalWidth: PropTypes.number.isRequired
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default React.memo(THead)
|
|
1
|
+
import PropTypes from 'prop-types'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import Th from './th'
|
|
4
|
+
|
|
5
|
+
const THead = ({ headerGroups, totalWidth }) => {
|
|
6
|
+
return (
|
|
7
|
+
<thead className='gm-table-x-thead'>
|
|
8
|
+
{headerGroups.map((headerGroup, i) => (
|
|
9
|
+
<tr key={i} className='gm-table-x-tr'>
|
|
10
|
+
{headerGroup.headers.map((column, i) => (
|
|
11
|
+
<Th key={i} column={column} totalWidth={totalWidth} />
|
|
12
|
+
))}
|
|
13
|
+
</tr>
|
|
14
|
+
))}
|
|
15
|
+
</thead>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
THead.whyDidYouRender = true
|
|
20
|
+
|
|
21
|
+
THead.propTypes = {
|
|
22
|
+
headerGroups: PropTypes.array.isRequired,
|
|
23
|
+
totalWidth: PropTypes.number.isRequired
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default React.memo(THead)
|