Skip to content

Commit

Permalink
feat: #1789
Browse files Browse the repository at this point in the history
  • Loading branch information
Wugaoliang committed Jun 22, 2021
1 parent 237e9af commit 7d88ae0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 48 deletions.
21 changes: 6 additions & 15 deletions components/table/HeaderTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Checkbox from '../checkbox'
import { flatTreeData, setDepth, getLeafChildren, groupDataByDepth } from './util'
import { Resizable } from 'react-resizable'

const HeaderTable = ({ bodyWidth, rightFixedIndex }) => {
const HeaderTable = ({ rightFixedIndex }) => {
const {
rowSelection,
data,
Expand All @@ -32,7 +32,7 @@ const HeaderTable = ({ bodyWidth, rightFixedIndex }) => {
resizable,
setting,
onHeaderRow,
ceiling,
sticky,
disabledData
} = useContext(TableContext)
const [isAllChecked, setIsAllChecked] = useState(false)
Expand Down Expand Up @@ -257,23 +257,14 @@ const HeaderTable = ({ bodyWidth, rightFixedIndex }) => {
style={{
borderLeft: bordered && '1px solid #e7e7e7',
borderTop: bordered && '1px solid #e7e7e7',
overflow: 'hidden',
boxShadow: maxHeight && '0px 2px 6px 0px rgba(0,0,0,0.12)',
position: 'relative'
position: sticky ? 'sticky' : 'relative',
top: sticky && stickyTop,
zIndex: 10
}}
>
{setting && <SettingMenu />}
<div
className={`${prefix}__header`}
key="normal"
ref={headerTableRef}
style={{
overflow: 'hidden',
width: ceiling ? bodyWidth : 'auto',
position: ceiling ? 'fixed' : 'static',
top: ceiling && stickyTop
}}
>
<div className={`${prefix}__header`} key="normal" ref={headerTableRef}>
<table style={{ width: '100%' }} ref={headerInner}>
<colgroup>
{columnsgroup.map((c, index) => {
Expand Down
34 changes: 3 additions & 31 deletions components/table/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Table = ({
showColHighlight,
prefix = 'hi-table',
fixedToColumn,
sticky: _ceiling,
sticky,
stickyTop = 0,
setting,
onLoadChildren,
Expand All @@ -63,7 +63,6 @@ const Table = ({
const [columns, setColumns] = useState(propsColumns)
const hiTable = useRef(null)
const disabledData = useRef([])
const [ceiling, setCeiling] = useState(false)
const [activeSorterColumn, setActiveSorterColumn] = useState(null)
const [activeSorterType, setActiveSorterType] = useState(null)
const [highlightColumns, setHighlightColumns] = useState([])
Expand Down Expand Up @@ -197,33 +196,6 @@ const Table = ({
const alignRightColumns = columns.filter((c) => c.align === 'right').map((col) => col.dataKey)
// baseTable
const baseTable = useRef(null)
const [baseTableWidth, setBaseTableWidth] = useState('100%')
const clientWidth = baseTable.current && baseTable.current.clientWidth
useEffect(() => {
setBaseTableWidth(clientWidth)
}, [clientWidth])

useEffect(() => {
if (_ceiling) {
window.addEventListener(
'scroll',
(e) => {
if (
hiTable &&
hiTable.current &&
hiTable.current.getBoundingClientRect().top <= stickyTop &&
hiTable.current.getBoundingClientRect().bottom >= stickyTop + 35
) {
setCeiling(true)
syncScrollLeft(bodyTableRef.current.scrollLeft, stickyHeaderRef.current)
} else {
setCeiling(false)
}
},
true
)
}
}, [_ceiling, stickyTop])

useEffect(() => {
if (dataSource) {
Expand Down Expand Up @@ -258,7 +230,7 @@ const Table = ({
onExpand,
realColumnsWidth,
setRealColumnsWidth,
ceiling,
sticky,
stickyTop,
// 排序逻辑
activeSorterColumn,
Expand Down Expand Up @@ -319,7 +291,7 @@ const Table = ({
>
{/* Normal table 普通表格 */}
<div className={`${prefix}__container`} ref={baseTable}>
<HeaderTable bodyWidth={baseTableWidth} />
<HeaderTable />
<BodyTable fatherRef={hiTable} emptyContent={emptyContent} />
{/* 显示阴影 */}
{scrollSize.scrollLeft > 0 && realLeftFixedColumns.length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion components/table/style/Table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

.#{$table} {
position: relative;
overflow: hidden;
// overflow: hidden;

&__container {
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion components/table/style/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
}

&__header {
overflow-x: scroll;
overflow: hidden;
position: relative;

> table {
Expand Down
2 changes: 2 additions & 0 deletions docs/demo/table/section-special.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ class Demo extends React.Component {
columns={this.columns}
fixedToColumn={{left:'number', right: 'gender'}}
data={this.data}
stickyTop={63}
sticky
rowSelection={{
selectedRowKeys: this.state.selectedRowKeys,
onChange: selectedRowKeys => {
Expand Down

0 comments on commit 7d88ae0

Please sign in to comment.