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 dragging for fixed columns #74

Merged
merged 1 commit into from
Nov 2, 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
2 changes: 1 addition & 1 deletion examples/ReorderExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ReorderExample extends React.Component {
isReorderable={true}
header={<Cell>{columnTitles[columnKey]}</Cell>}
cell={<TextCell data={dataList} />}
fixed={i === 0}
fixed={i <= 1}
width={columnWidths[columnKey]}
/>;
})}
Expand Down
31 changes: 20 additions & 11 deletions src/FixedDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,15 @@ var FixedDataTable = React.createClass({
/*number*/ left,
/*object*/ event
) {
var isFixed = !!this.state.headFixedColumns.find(function(column) {
return column.props.columnKey === columnKey;
});

this.setState({
isColumnReordering: true,
columnReorderingData: {
dragDistance: 0,
isFixed: isFixed,
scrollStart: this.state.scrollX,
columnKey: columnKey,
columnWidth: width,
Expand All @@ -727,21 +732,25 @@ var FixedDataTable = React.createClass({
reorderingData.columnBefore = undefined;
reorderingData.columnAfter = undefined;

var isFixedColumn = this.state.columnReorderingData.isFixed;
var scrollX = this.state.scrollX;
//Relative dragX position on scroll
var dragX = reorderingData.originalLeft - reorderingData.scrollStart + reorderingData.dragDistance;

var fixedColumnsWidth = this.state.bodyFixedColumns.reduce((sum, column) => sum + column.props.width, 0);
var relativeWidth = this.props.width - fixedColumnsWidth;
if (!isFixedColumn) {
Copy link
Member

Choose a reason for hiding this comment

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

interesting, so this means we won't scroll through fixed columns but I guess there's no use case for that.

//Relative dragX position on scroll
var dragX = reorderingData.originalLeft - reorderingData.scrollStart + reorderingData.dragDistance;

//Scroll the table left or right if we drag near the edges of the table
if (dragX > relativeWidth - DRAG_SCROLL_BUFFER) {
scrollX = Math.min(scrollX + DRAG_SCROLL_SPEED, this.state.maxScrollX);
} else if (dragX <= DRAG_SCROLL_BUFFER) {
scrollX = Math.max(scrollX - DRAG_SCROLL_SPEED, 0);
}
var fixedColumnsWidth = this.state.bodyFixedColumns.reduce((sum, column) => sum + column.props.width, 0);
var relativeWidth = this.props.width - fixedColumnsWidth;

reorderingData.dragDistance += this.state.scrollX - reorderingData.scrollStart;
//Scroll the table left or right if we drag near the edges of the table
if (dragX > relativeWidth - DRAG_SCROLL_BUFFER) {
scrollX = Math.min(scrollX + DRAG_SCROLL_SPEED, this.state.maxScrollX);
} else if (dragX <= DRAG_SCROLL_BUFFER) {
scrollX = Math.max(scrollX - DRAG_SCROLL_SPEED, 0);
}

reorderingData.dragDistance += this.state.scrollX - reorderingData.scrollStart;
}

this.setState({
scrollX: scrollX,
Expand Down