Skip to content

Commit

Permalink
Fixing column drag scroll with cell recycling (#40)
Browse files Browse the repository at this point in the history
* Fixing column drag scroll with cell recycling

* Adding horizontal scroll callback

* CR
  • Loading branch information
KamranAsif committed Aug 3, 2016
1 parent 02dbb62 commit 5e11477
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
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;

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

0 comments on commit 5e11477

Please sign in to comment.