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

fix(selector): cell range selector was not working when at bottom #331

Merged
merged 5 commits into from
Feb 6, 2019
Merged
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
77 changes: 47 additions & 30 deletions plugins/slick.cellrangeselector.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@
var _isRightCanvas;
var _isBottomCanvas;

// Scrollings
var _scrollTop;
var _scrollLeft;

function init(grid) {
options = $.extend(true, {}, _defaults, options);
_decorator = options.cellDecorator || new Slick.CellRangeDecorator(grid, options);
_grid = grid;
_canvas = _grid.getCanvasNode();
_gridOptions = _grid.getOptions();
_handler
.subscribe(_grid.onScroll, handleScroll)
.subscribe(_grid.onDragInit, handleDragInit)
.subscribe(_grid.onDragStart, handleDragStart)
.subscribe(_grid.onDrag, handleDrag)
Expand All @@ -49,27 +54,32 @@
return _decorator;
}

function handleScroll(e, args) {
_scrollTop = args.scrollTop;
_scrollLeft = args.scrollLeft;
}

function handleDragInit(e, dd) {
// Set the active canvas node because the decorator needs to append its
// box to the correct canvas
_$activeCanvas = $( _grid.getActiveCanvasNode( e ) );
_$activeCanvas = $(_grid.getActiveCanvasNode(e));

var c = _$activeCanvas.offset();

_rowOffset = 0;
_columnOffset = 0;
_isBottomCanvas = _$activeCanvas.hasClass( 'grid-canvas-bottom' );
_isBottomCanvas = _$activeCanvas.hasClass('grid-canvas-bottom');

if ( _gridOptions.frozenRow > -1 && _isBottomCanvas ) {
_rowOffset = ( _gridOptions.frozenBottom ) ? $('.grid-canvas-bottom').height() : $('.grid-canvas-top').height();
if (_gridOptions.frozenRow > -1 && _isBottomCanvas) {
_rowOffset = (_gridOptions.frozenBottom) ? $('.grid-canvas-bottom').height() : $('.grid-canvas-top').height();
}
_isRightCanvas = _$activeCanvas.hasClass( 'grid-canvas-right' );
if ( _gridOptions.frozenColumn > -1 && _isRightCanvas ) {
_columnOffset = $('.grid-canvas-left').width();

_isRightCanvas = _$activeCanvas.hasClass('grid-canvas-right');

if (_gridOptions.frozenColumn > -1 && _isRightCanvas) {
_columnOffset = $('.grid-canvas-left').width();
}

// prevent the grid from cancelling drag'n'drop by default
e.stopImmediatePropagation();
}
Expand All @@ -88,11 +98,19 @@

_grid.focus();

var start = _grid.getCellFromPoint(
dd.startX - $(_canvas).offset().left,
dd.startY - $(_canvas).offset().top);
var startX = dd.startX - $(_canvas).offset().left;
if (_gridOptions.frozenColumn >= 0) {
startX += _scrollLeft;
}

var startY = dd.startY - $(_canvas).offset().top;
if (_gridOptions.frozenRow >= 0) {
startY += _scrollTop;
}

dd.range = {start: start, end: {}};
var start = _grid.getCellFromPoint(startX, startY);

dd.range = { start: start, end: {} };
_currentlySelectedRange = dd.range;
return _decorator.show(new Slick.Range(start.row, start.cell));
}
Expand All @@ -108,24 +126,23 @@
e.pageY - _$activeCanvas.offset().top + _rowOffset
);

if (_gridOptions.frozenColumn < 0) {
if (!_grid.canCellBeSelected(end.row, end.cell)) {
return;
}
} else {
// when having frozen column(s), we need to do extra checks
if ( (!_grid.canCellBeSelected( end.row, end.cell ) )
|| ( !_isRightCanvas && ( end.cell > _gridOptions.frozenColumn ) )
|| ( _isRightCanvas && ( end.cell <= _gridOptions.frozenColumn ) )
|| ( !_isBottomCanvas && ( end.row >= _gridOptions.frozenRow ) )
|| ( _isBottomCanvas && ( end.row < _gridOptions.frozenRow ) )
) {
return;
}
// ... frozen column(s),
if ( _gridOptions.frozenColumn >= 0 && (!_isRightCanvas && (end.cell > _gridOptions.frozenColumn)) || (_isRightCanvas && (end.cell <= _gridOptions.frozenColumn)) ) {
return;
}

// ... or frozen row(s)
if ( _gridOptions.frozenRow >= 0 && (!_isBottomCanvas && (end.row >= _gridOptions.frozenRow)) || (_isBottomCanvas && (end.row < _gridOptions.frozenRow)) ) {
return;
}

// ... or regular grid (without any frozen options)
if (!_grid.canCellBeSelected(end.row, end.cell)) {
return;
}

dd.range.end = end;

_decorator.show(new Slick.Range(dd.range.start.row, dd.range.start.cell, end.row, end.cell));
}

Expand All @@ -147,7 +164,7 @@
)
});
}

function getCurrentRange() {
return _currentlySelectedRange;
}
Expand Down