-
Notifications
You must be signed in to change notification settings - Fork 423
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
Conversation
- the issue was that if user open the example "example-frozen-columns-and-rows-spreadsheet.html" and he scrolls completely at the bottom of the frozen grid (bottom right) and try to select a cell range, it was not selecting properly
@mpegithub could you please test this change and see if that works. I tried locally and it works. I need to do some more tests with few more examples to make sure it doesn't break anything (I need to test with and without frozen grids). The source of the code change is from X-Slickgrid - slick.cellrangeselector.js @6pac |
@mpegithub the code change was to remove the |
@mpegithub Tested with |
Hi, I test with some frozen rows and columns then scroll down and/or right => it is not good for me, always the same issue.
I think these computes ignore the scrolls offset. |
I used your correction but removed else statements in handleDrag function because it is possible to have frozen columns AND frozen rows. Next I add an event manager for scroll to get scollLeft and scrollTop values. Then, in handleDragStart function, I added these values to the start point coordinates only if frozen columns or frozen rows exist. This works for me with frozenColumn: 0 and frozenRow: 5 for example. Here is my code : (function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
"CellRangeSelector": CellRangeSelector
}
});
function CellRangeSelector(options) {
var _grid;
var _currentlySelectedRange;
var _canvas;
var _gridOptions;
var _$activeCanvas;
var _dragging;
var _decorator;
var _self = this;
var _handler = new Slick.EventHandler();
var _defaults = {
selectionCss: {
"border": "2px dashed blue"
}
};
// Frozen row & column variables
var _rowOffset;
var _columnOffset;
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)
.subscribe(_grid.onDragEnd, handleDragEnd);
}
function destroy() {
_handler.unsubscribeAll();
}
function getCellDecorator() {
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));
var c = _$activeCanvas.offset();
_rowOffset = 0;
_columnOffset = 0;
_isBottomCanvas = _$activeCanvas.hasClass('grid-canvas-bottom');
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();
}
// prevent the grid from cancelling drag'n'drop by default
e.stopImmediatePropagation();
}
function handleDragStart(e, dd) {
var cell = _grid.getCellFromEvent(e);
if (_self.onBeforeCellRangeSelected.notify(cell) !== false) {
if (_grid.canCellBeSelected(cell.row, cell.cell)) {
_dragging = true;
e.stopImmediatePropagation();
}
}
if (!_dragging) {
return;
}
_grid.focus();
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;
}
var start = _grid.getCellFromPoint(
// dd.startX - $(_canvas).offset().left,
// dd.startY - $(_canvas).offset().top);
startX, startY);
dd.range = { start: start, end: {} };
_currentlySelectedRange = dd.range;
return _decorator.show(new Slick.Range(start.row, start.cell));
}
function handleDrag(e, dd) {
if (!_dragging) {
return;
}
e.stopImmediatePropagation();
var end = _grid.getCellFromPoint(
e.pageX - _$activeCanvas.offset().left + _columnOffset,
e.pageY - _$activeCanvas.offset().top + _rowOffset
);
// ... 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)) {
console.log("1");
return;
}
dd.range.end = end;
_decorator.show(new Slick.Range(dd.range.start.row, dd.range.start.cell, end.row, end.cell));
}
function handleDragEnd(e, dd) {
if (!_dragging) {
return;
}
_dragging = false;
e.stopImmediatePropagation();
_decorator.hide();
_self.onCellRangeSelected.notify({
range: new Slick.Range(
dd.range.start.row,
dd.range.start.cell,
dd.range.end.row,
dd.range.end.cell
)
});
} |
@mpegithub |
Which examples ? Do you test with frozen column AND frozen rows then scroll to right and down in the right bottom part of the grid ? |
Ah sorry I wrote in earlier post
So 1 has frozen rows/columns and the other is a regular grid. Those are mainly the only few examples which have the cell range enabled. |
I don't understand, I tried with
|
damn you are right again, I forgot to scroll. The scrolling does screw it up. Then I don't know what else to try and I'm at work so my time is a bit limited. If I look at the 2 repos, Jlynh7 and X-Slickgrid (which is based of JLynch) have different approach but trying both and the issue still persist. All the code that I use to implement the frozen feature in this lib comes from the X-Slickgrid repo since it was the most used and last updated. |
Have you look at my last proposition with an handle on scroll event in earlier post ? |
You mean your post here? I thought you only removed the |
The following modifications are working for me :
|
If that the same code as your previous post? |
It seems that the end of code is missing in my previous post.. See below the full file : |
I pushed the changes from that earlier post you had. I tried both examples and also scroll in both, it seems to work correctly now. Can you test on your side. |
I tested, it's ok for me. |
Great, thanks for all your investigation, so are you ok if I merge the code now? |
Yes. |
Just a question, do you know if it is possible to make a selection using the shift key ? Do I miss an option of the plugin ? |
Hmm I don't think using shift would make any difference, this is a range selector so what are you expecting the shift to do? |
Click on top left cell, press and maintain shift key, then click on another cell to make the selection. |
The range selector uses the jquery drag, so I don't see the shift working with this, I assume it will be disregarded |
Ok, thanks for all ! |
I should say thanks to you since you're the one who provided the fix 😉 |
@mpegithub hmmm this is strange, I get errors thrown up in the console which were not showing before merging the PR. I don't think other PRs caused this issue though since I tried reverting manually some of the change and that has no effect. Found the issue, the 2 new variables |
@mpegithub |
reference issue #329
This is a Work in Progress (DO NOT MERGE YET)
We need to do some more test before merging