Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing column drag scroll with cell recycling #40

Merged
merged 3 commits into from
Aug 3, 2016
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 examples/ReorderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class ReorderExample extends React.Component {
{...this.props}>
{this.state.columnOrder.map(function (columnKey, i) {
return <Column
allowCellsRecycling={true}
columnKey={columnKey}
key={i}
isReorderable={true}
Expand Down
5 changes: 5 additions & 0 deletions src/FixedDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,11 @@ var FixedDataTable = React.createClass({
this.props.onColumnReorderEndCallback({
columnBefore, columnAfter, reorderColumn
});

var onHorizontalScroll = this.props.onHorizontalScroll;
if (this.state.columnReorderingData.scrollStart !== this.state.scrollX && onHorizontalScroll) {
onHorizontalScroll(this.state.scrollX)
};
},

_areColumnSettingsIdentical(
Expand Down
3 changes: 2 additions & 1 deletion src/FixedDataTableCellDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ var FixedDataTableCellDefault = React.createClass({
},

render() {
var {height, width, style, className, children, columnKey, ...props} = this.props;
//Remove some props like columnKey and rowIndex so we don't pass it into the div
var {height, width, style, className, children, columnKey, rowIndex, ...props} = this.props;
Copy link
Member

Choose a reason for hiding this comment

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

Interesting destructing to remove props...
Confused me for a second so might be worth adding a comment as to why it's done. Maybe this is just a common pattern I haven't seen yet though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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


var innerStyle = {
height,
Expand Down
3 changes: 2 additions & 1 deletion src/FixedDataTableCellGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ var FixedDataTableCellGroupImpl = React.createClass({
var currentPosition = 0;
for (var i = 0, j = columns.length; i < j; i++) {
var columnProps = columns[i].props;
if (!columnProps.allowCellsRecycling || (
var recycable = columnProps.allowCellsRecycling && !isColumnReordering;
if (!recycable || (
currentPosition - props.left <= props.width &&
currentPosition - props.left + columnProps.width >= 0)) {
var key = 'cell_' + i;
Expand Down
8 changes: 6 additions & 2 deletions src/FixedDataTableColumnReorderHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var FixedDataTableColumnReorderHandle = React.createClass({

componentWillUnmount() {
if (this._mouseMoveTracker) {
cancelAnimationFrame(this.frameId);
this.frameId = null;
this._mouseMoveTracker.releaseMouseMoves();
this._mouseMoveTracker = null;
}
Expand Down Expand Up @@ -101,7 +103,7 @@ var FixedDataTableColumnReorderHandle = React.createClass({

this._distance = 0;
this._animating = true;
requestAnimationFrame(this._updateState);
this.frameId = requestAnimationFrame(this._updateState);
},

_onMove(/*number*/ deltaX) {
Expand All @@ -110,13 +112,15 @@ var FixedDataTableColumnReorderHandle = React.createClass({

_onColumnReorderEnd() {
this._animating = false;
cancelAnimationFrame(this.frameId);
this.frameId = null;
this._mouseMoveTracker.releaseMouseMoves();
this.props.onColumnReorderEnd();
},

_updateState() {
if (this._animating) {
requestAnimationFrame(this._updateState)
this.frameId = requestAnimationFrame(this._updateState)
}
this.setState({
dragDistance: this._distance
Expand Down