Skip to content

Commit

Permalink
dnd col reordering after horizontal scroll working
Browse files Browse the repository at this point in the history
  • Loading branch information
stevewirts committed Jan 6, 2015
1 parent 6f99edf commit b399977
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 37 deletions.
4 changes: 2 additions & 2 deletions features/fin-hypergrid-feature-column-moving.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
handleMouseDrag: function(grid, event) {

var gridCell = event.gridCell;
var scrollLeft = grid.getHScrollValue();
//var scrollLeft = grid.getHScrollValue();

var x, y;

if (this.isFixedRow(grid,event) && this.dragArmed && !this.dragging) {
this.dragging = true;
this.dragCol = gridCell.x - grid.getFixedColCount() + scrollLeft;
this.dragCol = gridCell.x - grid.getFixedColCount();
this.dragOffset = event.mousePoint.x;
this.detachChain();
x = event.primitiveEvent.detail.mouse.x - this.dragOffset;
Expand Down
28 changes: 11 additions & 17 deletions fin-hypergrid.html
Original file line number Diff line number Diff line change
Expand Up @@ -1680,9 +1680,9 @@
},

createFloatColumn: function(colIndex) {
// var x = 0;
var scrollLeft = this.getHScrollValue();
var numFixedCols = this.getFixedColCount();
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex) : this.getColumnWidth(colIndex + this.getHScrollValue());
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex + scrollLeft) : this.getColumnWidth(colIndex + scrollLeft);
var d = this.floatColumn;
d.setAttribute('width', colWidth + 'px');
d.setAttribute('height', this.clientHeight + 'px');
Expand All @@ -1704,37 +1704,30 @@

//do the animation and swap the columns
//we need a better name
floatColumnTo: function(columnDragDirection, colIndex) {
noop(colIndex);


floatColumnTo: function(columnDragDirection) {
var scrollLeft = this.getHScrollValue();
var floaterIndex = this.columnRenderOverridesCache.floater.colIndex;
var draggerIndex = this.columnRenderOverridesCache.dragger.colIndex;
var numFixedCols = this.getFixedColCount();
var draggerStartX;
var floaterStartX;
if (columnDragDirection) {
var dw = this.getColumnWidth(draggerIndex);
var fw = this.getColumnWidth(floaterIndex);
var fsx = this.renderer.renderedColWidths[floaterIndex + numFixedCols];
var drsx = this.renderer.renderedColWidths[draggerIndex + numFixedCols];
noop(dw, fw, fsx, drsx);
draggerStartX = this.renderer.renderedColWidths[draggerIndex + numFixedCols];
floaterStartX = draggerStartX + this.getColumnWidth(floaterIndex);
floaterStartX = draggerStartX + this.getColumnWidth(floaterIndex + scrollLeft);

this.columnRenderOverridesCache.dragger.startX = floaterStartX;
this.columnRenderOverridesCache.floater.startX = draggerStartX;

floaterStartX = draggerStartX + this.getColumnWidth(draggerIndex);
floaterStartX = draggerStartX + this.getColumnWidth(draggerIndex + scrollLeft);

} else {
floaterStartX = this.renderer.renderedColWidths[floaterIndex + numFixedCols];
draggerStartX = floaterStartX + this.getColumnWidth(draggerIndex);
draggerStartX = floaterStartX + this.getColumnWidth(draggerIndex + scrollLeft);

this.columnRenderOverridesCache.dragger.startX = floaterStartX;
this.columnRenderOverridesCache.floater.startX = draggerStartX;
}
this.getBehavior().swapColumns(draggerIndex, floaterIndex);
this.getBehavior().swapColumns(draggerIndex + scrollLeft, floaterIndex + scrollLeft);
this.columnRenderOverridesCache.dragger.colIndex = floaterIndex;
this.columnRenderOverridesCache.floater.colIndex = draggerIndex;

Expand Down Expand Up @@ -1779,8 +1772,9 @@
},

createDragColumn: function(x, colIndex) {
var scrollLeft = this.getHScrollValue();
var numFixedCols = this.getFixedColCount();
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex) : this.getColumnWidth(colIndex);
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex + scrollLeft) : this.getColumnWidth(colIndex + scrollLeft);
var d = this.dragger;
d.setAttribute('width', colWidth + 'px');
d.setAttribute('height', this.clientHeight + 'px');
Expand Down Expand Up @@ -1820,7 +1814,7 @@
var threshold = columnDragDirection ? 1 : 0;
if (colDif > 1 || colDif < 0) {
this.createFloatColumn(overCol - threshold);
this.floatColumnTo(columnDragDirection, dragColumnIndex);
this.floatColumnTo(columnDragDirection);
}
},

Expand Down
28 changes: 11 additions & 17 deletions fin-hypergrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1563,9 +1563,9 @@
},

createFloatColumn: function(colIndex) {
// var x = 0;
var scrollLeft = this.getHScrollValue();
var numFixedCols = this.getFixedColCount();
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex) : this.getColumnWidth(colIndex + this.getHScrollValue());
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex + scrollLeft) : this.getColumnWidth(colIndex + scrollLeft);
var d = this.floatColumn;
d.setAttribute('width', colWidth + 'px');
d.setAttribute('height', this.clientHeight + 'px');
Expand All @@ -1587,37 +1587,30 @@

//do the animation and swap the columns
//we need a better name
floatColumnTo: function(columnDragDirection, colIndex) {
noop(colIndex);


floatColumnTo: function(columnDragDirection) {
var scrollLeft = this.getHScrollValue();
var floaterIndex = this.columnRenderOverridesCache.floater.colIndex;
var draggerIndex = this.columnRenderOverridesCache.dragger.colIndex;
var numFixedCols = this.getFixedColCount();
var draggerStartX;
var floaterStartX;
if (columnDragDirection) {
var dw = this.getColumnWidth(draggerIndex);
var fw = this.getColumnWidth(floaterIndex);
var fsx = this.renderer.renderedColWidths[floaterIndex + numFixedCols];
var drsx = this.renderer.renderedColWidths[draggerIndex + numFixedCols];
noop(dw, fw, fsx, drsx);
draggerStartX = this.renderer.renderedColWidths[draggerIndex + numFixedCols];
floaterStartX = draggerStartX + this.getColumnWidth(floaterIndex);
floaterStartX = draggerStartX + this.getColumnWidth(floaterIndex + scrollLeft);

this.columnRenderOverridesCache.dragger.startX = floaterStartX;
this.columnRenderOverridesCache.floater.startX = draggerStartX;

floaterStartX = draggerStartX + this.getColumnWidth(draggerIndex);
floaterStartX = draggerStartX + this.getColumnWidth(draggerIndex + scrollLeft);

} else {
floaterStartX = this.renderer.renderedColWidths[floaterIndex + numFixedCols];
draggerStartX = floaterStartX + this.getColumnWidth(draggerIndex);
draggerStartX = floaterStartX + this.getColumnWidth(draggerIndex + scrollLeft);

this.columnRenderOverridesCache.dragger.startX = floaterStartX;
this.columnRenderOverridesCache.floater.startX = draggerStartX;
}
this.getBehavior().swapColumns(draggerIndex, floaterIndex);
this.getBehavior().swapColumns(draggerIndex + scrollLeft, floaterIndex + scrollLeft);
this.columnRenderOverridesCache.dragger.colIndex = floaterIndex;
this.columnRenderOverridesCache.floater.colIndex = draggerIndex;

Expand Down Expand Up @@ -1662,8 +1655,9 @@
},

createDragColumn: function(x, colIndex) {
var scrollLeft = this.getHScrollValue();
var numFixedCols = this.getFixedColCount();
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex) : this.getColumnWidth(colIndex);
var colWidth = colIndex < 0 ? this.getFixedColumnWidth(numFixedCols + colIndex + scrollLeft) : this.getColumnWidth(colIndex + scrollLeft);
var d = this.dragger;
d.setAttribute('width', colWidth + 'px');
d.setAttribute('height', this.clientHeight + 'px');
Expand Down Expand Up @@ -1703,7 +1697,7 @@
var threshold = columnDragDirection ? 1 : 0;
if (colDif > 1 || colDif < 0) {
this.createFloatColumn(overCol - threshold);
this.floatColumnTo(columnDragDirection, dragColumnIndex);
this.floatColumnTo(columnDragDirection);
}
},

Expand Down
2 changes: 1 addition & 1 deletion fin-hypergrid.min.html

Large diffs are not rendered by default.

0 comments on commit b399977

Please sign in to comment.