Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
szse
Overview
Overview
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
zhaochengxiang
szse
Commits
fb835f70
Commit
fb835f70
authored
Sep 15, 2022
by
zhaochengxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
虚拟滚动
parent
c09b2491
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
ModelTable.jsx
src/view/Manage/Model/Component/ModelTable.jsx
+1
-1
index.tsx
src/view/Manage/VirtualTable/index.tsx
+8
-5
No files found.
src/view/Manage/Model/Component/ModelTable.jsx
View file @
fb835f70
...
...
@@ -507,7 +507,7 @@ const ModelTable = (props) => {
checkable
columns=
{
columns
}
// rows={Array.from({ length: 10000 }).map((_, i) => ({
// name:
'test'
,
// name:
`test${i}`
,
// }))}
rows=
{
data
||
[]
}
rowHeight=
{
51
}
...
...
src/view/Manage/VirtualTable/index.tsx
View file @
fb835f70
import
React
,
{
useCallback
,
useEffect
,
useMemo
,
useState
,
forwardRef
}
from
'react'
;
import
React
,
{
useCallback
,
useEffect
,
useMemo
,
useState
,
forwardRef
,
useRef
}
from
'react'
;
import
DataGrid
,
{
Column
,
DataGridProps
,
Row
as
GridRow
,
RowsChangeData
,
SortColumn
,
SortIconProps
,
SelectColumn
}
from
'react-data-grid'
;
import
type
{
DataGridHandle
,
CheckboxFormatterProps
}
from
'react-data-grid'
;
import
{
Checkbox
,
Empty
}
from
'antd'
;
...
...
@@ -142,6 +142,8 @@ function FC<Row extends RowData, SR, K extends React.Key = React.Key>(props: Dat
const
[
pagination
,
setPagination
]
=
useState
({
pageNum
:
1
,
pageSize
:
defaultPageSize
});
const
{
pageNum
,
pageSize
}
=
pagination
;
const
prevScrollTopRef
=
useRef
(
0
)
useEffect
(()
=>
{
if
(
rows
)
{
setPagination
(
prev
=>
{
...
...
@@ -159,7 +161,7 @@ function FC<Row extends RowData, SR, K extends React.Key = React.Key>(props: Dat
},
[
scrollRowIndex
])
useEffect
(()
=>
{
const
newRows
=
[...
paginate
(
rows
,
pageNum
,
pageSize
)];
let
newRows
=
[...
rows
]
if
(
sortColumns
.
length
>
0
)
{
newRows
// .filter(item => item.__type__ !== RowType.Detail)
...
...
@@ -175,6 +177,7 @@ function FC<Row extends RowData, SR, K extends React.Key = React.Key>(props: Dat
})
}
newRows
=
paginate
(
newRows
,
pageNum
,
pageSize
);
(
newRows
||
[]).
forEach
((
item
,
index
)
=>
{
item
.
index
=
`
${(
pageNum
-
1
)
*
pageSize
+
index
+
1
}
`
;
})
...
...
@@ -216,13 +219,13 @@ function FC<Row extends RowData, SR, K extends React.Key = React.Key>(props: Dat
// 处理滚动
const
handleScroll
=
useCallback
((
event
:
React
.
UIEvent
<
HTMLDivElement
>
)
=>
{
if
(
isAtTop
(
event
))
{
if
(
isAtTop
(
event
)
&&
prevScrollTopRef
.
current
>
event
.
currentTarget
.
scrollTop
)
{
if
(
pageNum
>
1
)
{
setPagination
(
prev
=>
{
return
{...
prev
,
pageNum
:
prev
.
pageNum
-
1
}
})
}
}
else
if
(
isAtBottom
(
event
))
{
}
else
if
(
isAtBottom
(
event
)
&&
prevScrollTopRef
.
current
<
event
.
currentTarget
.
scrollTop
)
{
if
(
rows
?.
length
>
pageNum
*
pageSize
)
{
event
.
currentTarget
.
scrollTop
=
0
;
setPagination
(
prev
=>
{
...
...
@@ -231,7 +234,7 @@ function FC<Row extends RowData, SR, K extends React.Key = React.Key>(props: Dat
}
}
// loadMoreRows?.(rows.length)
prevScrollTopRef
.
current
=
event
.
currentTarget
.
scrollTop
;
},
[
loadMoreRows
,
rows
,
pageNum
])
return
(
...
...
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