Fix drag selection
parent
f4ea9e29b1
commit
c744294335
35
treegrid.js
35
treegrid.js
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Very simple and fast tree grid/table, compatible with dynamic loading and jQuery fixedHeaderTable
|
* Very simple and fast tree grid/table, compatible with dynamic loading and jQuery fixedHeaderTable
|
||||||
* License: MPL 2.0+, (c) Vitaliy Filippov 2016+
|
* License: MPL 2.0+, (c) Vitaliy Filippov 2016+
|
||||||
* Version: 2016-03-25
|
* Version: 2016-04-04
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,6 +211,7 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode)
|
||||||
{
|
{
|
||||||
dragDiv = document.createElement('div');
|
dragDiv = document.createElement('div');
|
||||||
dragDiv.className = 'selection-rect';
|
dragDiv.className = 'selection-rect';
|
||||||
|
dragDiv.style.display = 'none';
|
||||||
document.body.appendChild(dragDiv);
|
document.body.appendChild(dragDiv);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -220,7 +221,14 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode)
|
||||||
if (startDrag)
|
if (startDrag)
|
||||||
{
|
{
|
||||||
evt = getEventCoord(evt);
|
evt = getEventCoord(evt);
|
||||||
dragDiv.style.display = 'block';
|
if (dragDiv.style.display == 'none')
|
||||||
|
{
|
||||||
|
if ((startDrag[0] < evt.pageX-10 || startDrag[0] > evt.pageX+10) &&
|
||||||
|
(startDrag[1] < evt.pageY-10 || startDrag[1] > evt.pageY+10))
|
||||||
|
dragDiv.style.display = 'block';
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (startDrag[0] < evt.pageX)
|
if (startDrag[0] < evt.pageX)
|
||||||
{
|
{
|
||||||
dragDiv.style.left = startDrag[0]+'px';
|
dragDiv.style.left = startDrag[0]+'px';
|
||||||
|
@ -264,14 +272,23 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode)
|
||||||
y1 = t;
|
y1 = t;
|
||||||
}
|
}
|
||||||
startDrag = null;
|
startDrag = null;
|
||||||
if (x2 > x1+10 && y2 > y1+10)
|
function doSelect()
|
||||||
|
{
|
||||||
|
if (!this.parentNode._node)
|
||||||
|
return;
|
||||||
|
var i = self.getNodeIndex(this);
|
||||||
|
if (!self.onCellSelect || self.onCellSelect(this.parentNode._node, i, this))
|
||||||
|
this.className += ' selected';
|
||||||
|
}
|
||||||
|
if (x2 > x1+10 && y2 > y1+10)
|
||||||
|
rectangleSelect(self.table.getElementsByTagName('td'), x1, y1, x2, y2, doSelect);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var t = evt.target || evt.srcElement;
|
||||||
|
doSelect.apply(t);
|
||||||
|
}
|
||||||
|
if (x2 > x1+10 && y2 > y1+10 || evt.shiftKey)
|
||||||
{
|
{
|
||||||
rectangleSelect(self.table.getElementsByTagName('td'), x1, y1, x2, y2, function()
|
|
||||||
{
|
|
||||||
var i = self.getNodeIndex(this);
|
|
||||||
if (!self.onCellSelect || self.onCellSelect(this.parentNode._node, i, this))
|
|
||||||
this.className += ' selected';
|
|
||||||
});
|
|
||||||
if (document.selection)
|
if (document.selection)
|
||||||
document.selection.empty();
|
document.selection.empty();
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue