Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenshaokai
jinfa-platform
Commits
5ad7d1c0
Commit
5ad7d1c0
authored
Apr 25, 2022
by
XieZhiXiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复表格头存在固定布局列情况下,拖拽Col到最后面出现不能正常展示表格列的问题
parent
66c92236
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
18 deletions
+31
-18
CustomColumnsConfigureModal.tsx
...er/CustomColumnsConfigure/CustomColumnsConfigureModal.tsx
+1
-1
DraggableHeaderRow.tsx
src/components/SortableTableHeader/DraggableHeaderRow.tsx
+9
-1
README.md
src/components/SortableTableHeader/README.md
+9
-7
useSortableColumns.ts
src/components/SortableTableHeader/useSortableColumns.ts
+10
-7
index.tsx
src/pages/transaction/purchaseOrder/index.tsx
+1
-1
index.tsx
src/pages/transaction/saleOrder/index.tsx
+1
-1
No files found.
src/components/SortableTableHeader/CustomColumnsConfigure/CustomColumnsConfigureModal.tsx
View file @
5ad7d1c0
...
...
@@ -6,7 +6,7 @@ import { Modal, Checkbox, message } from 'antd';
import
{
CloseOutlined
,
HolderOutlined
}
from
'@ant-design/icons'
;
import
{
ColumnType
}
from
'antd/lib/table/interface'
;
import
{
CheckboxValueType
}
from
'antd/lib/checkbox/Group'
;
import
{
ReactSortable
,
ItemInterface
}
from
"react-sortablejs"
;
import
{
ReactSortable
,
ItemInterface
}
from
'react-sortablejs'
;
import
{
SortableColumnType
}
from
'../interface'
;
import
'./index.less'
;
...
...
src/components/SortableTableHeader/DraggableHeaderRow.tsx
View file @
5ad7d1c0
...
...
@@ -2,7 +2,7 @@
* @Description 可拖拽的表格头部 Row 组件
*/
import
React
,
{
useMemo
}
from
'react'
;
import
{
ReactSortable
,
ItemInterface
}
from
'react-sortablejs'
;
import
{
ReactSortable
,
ItemInterface
,
Sortable
,
Store
}
from
'react-sortablejs'
;
import
{
ColumnType
}
from
'antd/lib/table/interface'
;
import
{
SortableContextProvider
}
from
'./context'
;
...
...
@@ -66,6 +66,13 @@ const DraggableHeaderRow: React.FC<DraggableHeaderRowProps> = (props) => {
setColumns
?.(
newColumns
as
SortableColumn
[]);
};
const
handleMove
=
(
evt
:
Sortable
.
MoveEvent
,
originalEvent
:
Event
,
sortable
:
Sortable
,
store
:
Store
):
(
boolean
|
void
|
1
|
-
1
)
=>
{
if
(
!
evt
.
related
.
className
.
includes
(
'active'
))
{
return
false
;
}
return
true
;
};
return
(
<
ReactSortable
list=
{
columns
as
ItemInterface
[]
}
...
...
@@ -73,6 +80,7 @@ const DraggableHeaderRow: React.FC<DraggableHeaderRowProps> = (props) => {
tag=
"tr"
handle=
".columns-draggable-handle"
dataIdAttr=
"data-id"
onMove=
{
handleMove
}
>
<
SortableContextProvider
value=
{
{
...
...
src/components/SortableTableHeader/README.md
View file @
5ad7d1c0
...
...
@@ -5,6 +5,8 @@
步骤 2: 将页面中定义给 Table 的 columns 传给 useSortableColumns,并设置Table组件的属性columns 为 useSortableColumns 返回的 columns
步骤 3: 给 Table 组件设置对应 components、onHeaderRow 属性
<font
color=
RoyalBlue
>
*
注:如果表格使用了 rowSelection 属性,记得 useSortableColumns 第二个参数传递 true,否则会出现不能正常拖拽、伸缩
</font>
```
tsx
import
React
from
'react'
;
import
{
Table
}
from
'antd'
;
...
...
@@ -51,7 +53,7 @@ const SortableTableList: React.FC<any> = () => {
},
];
const
[
columns
,
setColumns
]
=
useSortableColumns
<
UserInfoType
>
(
defaultColumns
);
const
[
columns
,
setColumns
]
=
useSortableColumns
<
UserInfoType
>
(
defaultColumns
,
false
);
return
(
<
Table
...
...
@@ -123,7 +125,7 @@ const SortableTableList: React.FC<any> = () => {
},
];
const
[
columns
,
setColumns
]
=
useSortableColumns
<
UserInfoType
>
(
defaultColumns
);
const
[
columns
,
setColumns
]
=
useSortableColumns
<
UserInfoType
>
(
defaultColumns
,
false
);
return
(
<
div
>
...
...
@@ -149,8 +151,8 @@ const SortableTableList: React.FC<any> = () => {
cell
:
SortableTableHeader
.
DraggableHeaderCell
,
},
}
}
onHeaderRow=
{
(
_
,
index
)
=>
({
columns
,
onHeaderRow=
{
(
internalColumns
,
index
)
=>
({
columns
:
internalColumns
,
index
,
setColumns
,
})
as
any
}
...
...
@@ -194,7 +196,7 @@ const dataSource: UserInfoType[] = [
const
SortableTableList
:
React
.
FC
<
any
>
=
()
=>
{
const
[
columns
,
setColumns
]
=
useSortableColumns
<
UserInfoType
>
([]);
const
[
columns
,
setColumns
]
=
useSortableColumns
<
UserInfoType
>
([]
,
false
);
const
customColumnsConfigureRef
=
useRef
<
CustomColumnsConfigureRef
|
null
>
(
null
);
...
...
@@ -254,8 +256,8 @@ const SortableTableList: React.FC<any> = () => {
cell
:
SortableTableHeader
.
DraggableHeaderCell
,
},
}
}
onHeaderRow=
{
(
_
,
index
)
=>
({
columns
,
onHeaderRow=
{
(
internalColumns
,
index
)
=>
({
columns
:
internalColumns
,
index
,
setColumns
,
})
as
any
}
...
...
src/components/SortableTableHeader/useSortableColumns.ts
View file @
5ad7d1c0
...
...
@@ -6,9 +6,12 @@ import { ColumnType } from 'antd/lib/table/interface';
import
{
SortableColumn
}
from
'./DraggableHeaderRow'
;
import
{
SortableColumnType
}
from
'./interface'
;
// fix: && item.dataIndex 是为了判断 给Table传入了 rowSelection 的情况,这种情况下columns最前面会多出一项(勾选项)
const
isRowSelectionCol
=
(
item
:
ColumnType
<
any
>
)
=>
!
item
.
dataIndex
;
// 拓展 th 属性
// Antd的Table组件,如果想给 th 添加额外的属性只能通过 onHeaderCell
const
normailizeAdditionalHeaderCell
=
(
dataSource
:
ColumnType
<
any
>
[])
=>
{
const
normailizeAdditionalHeaderCell
=
(
dataSource
:
ColumnType
<
any
>
[]
,
hasRowSelection
:
boolean
)
=>
{
const
ret
:
SortableColumn
[]
=
[];
if
(
!
Array
.
isArray
)
{
return
ret
;
...
...
@@ -16,15 +19,15 @@ const normailizeAdditionalHeaderCell = (dataSource: ColumnType<any>[]) => {
dataSource
.
forEach
((
item
:
ColumnType
<
any
>
,
index
)
=>
{
const
commonProps
=
{
id
:
item
.
dataIndex
as
string
,
draggable
:
!
item
.
fixed
&&
item
.
dataIndex
,
// fix: && item.dataIndex 是为了判断 给Table传入了 rowSelection 的情况,这种情况下columns最前面会多出一项(勾选项)
resizable
:
index
!==
dataSource
.
length
-
1
&&
item
.
dataIndex
,
draggable
:
!
item
.
fixed
&&
!
isRowSelectionCol
(
item
),
resizable
:
index
!==
dataSource
.
length
-
1
&&
!
isRowSelectionCol
(
item
),
columnIndex
:
!
hasRowSelection
?
index
:
index
+
1
,
};
const
atom
=
{
...
item
,
onHeaderCell
:
()
=>
{
return
{
...(
item
.
onHeaderCell
?.(
item
)
||
{}),
columnIndex
:
index
,
...
commonProps
,
};
},
...
...
@@ -35,11 +38,11 @@ const normailizeAdditionalHeaderCell = (dataSource: ColumnType<any>[]) => {
return
ret
;
};
const
useSortableColumns
=
<
R
>
(
defaultColumns
:
ColumnType
<
R
>
[]):
[
SortableColumnType
<
R
>
[],
(
value
:
ColumnType
<
R
>
[])
=>
void
]
=>
{
const
[
columns
,
setColumns
]
=
useState
(
normailizeAdditionalHeaderCell
(
defaultColumns
));
const
useSortableColumns
=
<
R
>
(
defaultColumns
:
ColumnType
<
R
>
[]
,
hasRowSelection
:
boolean
):
[
SortableColumnType
<
R
>
[],
(
value
:
ColumnType
<
R
>
[])
=>
void
]
=>
{
const
[
columns
,
setColumns
]
=
useState
(
normailizeAdditionalHeaderCell
(
defaultColumns
,
hasRowSelection
));
const
handleSetColumns
=
(
value
:
ColumnType
<
R
>
[])
=>
{
setColumns
(
normailizeAdditionalHeaderCell
(
value
));
setColumns
(
normailizeAdditionalHeaderCell
(
value
.
filter
((
item
)
=>
!
isRowSelectionCol
(
item
)),
hasRowSelection
));
};
return
[
columns
,
handleSetColumns
];
...
...
src/pages/transaction/purchaseOrder/index.tsx
View file @
5ad7d1c0
...
...
@@ -91,7 +91,7 @@ const PurchaseOrder: React.FC<PurchaseOrderProps> = (props) => {
}
}
const
[
columns
,
setColumns
]
=
useSortableColumns
<
GetOrderBuyerPageResponseDetail
>
(
secondColumns
());
const
[
columns
,
setColumns
]
=
useSortableColumns
<
GetOrderBuyerPageResponseDetail
>
(
secondColumns
()
,
false
);
const
fetchParams
=
useRef
<
any
>
({})
const
customColumnsConfigureRef
=
useRef
<
CustomColumnsConfigureRef
|
null
>
(
null
)
...
...
src/pages/transaction/saleOrder/index.tsx
View file @
5ad7d1c0
...
...
@@ -113,7 +113,7 @@ const SaleOrder: React.FC<SaleOrderProps> = () => {
}
}
const
[
columns
,
setColumns
]
=
useSortableColumns
<
GetOrderVendorPageResponseDetail
>
(
secondColumns
());
const
[
columns
,
setColumns
]
=
useSortableColumns
<
GetOrderVendorPageResponseDetail
>
(
secondColumns
()
,
true
);
const
{
roles
}
=
getAuth
()
||
{}
const
serversRoles
=
roles
.
filter
(
item
=>
item
[
'roleType'
]
===
MEMBER_ROLE_TYPE_SERVICE_CONSUMER
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment