Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
]
},
"dependencies": {
"component-classes": "^1.2.6",
"lodash.get": "^4.4.2",
"rc-util": "3.x",
"shallowequal": "^0.2.2",
Expand Down
25 changes: 18 additions & 7 deletions src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import shallowequal from 'shallowequal';
import addEventListener from 'rc-util/lib/Dom/addEventListener';
import ColumnManager from './ColumnManager';
import createStore from './createStore';
import classes from 'component-classes';

const Table = React.createClass({
propTypes: {
Expand Down Expand Up @@ -73,6 +74,7 @@ const Table = React.createClass({
let rows = [...props.data];
this.columnManager = new ColumnManager(props.columns, props.children);
this.store = createStore({ currentHoverKey: null });
this.setScrollPosition('left');

if (props.defaultExpandAllRows) {
for (let i = 0; i < rows.length; i++) {
Expand All @@ -87,7 +89,6 @@ const Table = React.createClass({
expandedRowKeys,
data: props.data,
currentHoverKey: null,
scrollPosition: 'left',
fixedColumnsHeadRowsHeight: [],
fixedColumnsBodyRowsHeight: [],
};
Expand Down Expand Up @@ -575,6 +576,16 @@ const Table = React.createClass({
return null;
},

setScrollPosition(position) {
this.scrollPosition = position;
if (this.tableNode) {
const { prefixCls } = this.props;
classes(this.tableNode)
.remove(new RegExp(`^${prefixCls}-scroll-position-.+$`))
.add(`${prefixCls}-scroll-position-${position}`);
}
},

syncFixedTableRowHeight() {
const { prefixCls } = this.props;
const headRows = this.refs.headTable ?
Expand Down Expand Up @@ -636,13 +647,13 @@ const Table = React.createClass({
bodyTable.scrollLeft = e.target.scrollLeft;
}
if (e.target.scrollLeft === 0) {
this.setState({ scrollPosition: 'left' });
this.setScrollPosition('left');
} else if (e.target.scrollLeft + 1 >=
e.target.children[0].getBoundingClientRect().width -
e.target.getBoundingClientRect().width) {
this.setState({ scrollPosition: 'right' });
} else if (this.state.scrollPosition !== 'middle') {
this.setState({ scrollPosition: 'middle' });
this.setScrollPosition('right');
} else if (this.scrollPosition !== 'middle') {
this.setScrollPosition('middle');
}
}
if (scroll.y) {
Expand Down Expand Up @@ -677,14 +688,14 @@ const Table = React.createClass({
if (props.useFixedHeader || (props.scroll && props.scroll.y)) {
className += ` ${prefixCls}-fixed-header`;
}
className += ` ${prefixCls}-scroll-position-${this.state.scrollPosition}`;
className += ` ${prefixCls}-scroll-position-${this.scrollPosition}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一开始会是 undefined 。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句感觉可以去掉。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里设置了

this.setScrollPosition('left');

要的,第一次渲染的时候要设置 left 的 class。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该说不写的话,一 render 设置的 class 就没了。


const isTableScroll = this.columnManager.isAnyColumnsFixed() ||
props.scroll.x ||
props.scroll.y;

return (
<div className={className} style={props.style}>
<div ref={node => (this.tableNode = node)} className={className} style={props.style}>
{this.getTitle()}
<div className={`${prefixCls}-content`}>
{this.columnManager.isAnyColumnsLeftFixed() &&
Expand Down