Fix cell editing with sticky headers
parent
c465fb4ed3
commit
603e472e72
17
treegrid.js
17
treegrid.js
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Very simple and fast tree grid/table, compatible with dynamic loading and stickyheaders.js
|
||||
* License: MPL 2.0+, (c) Vitaliy Filippov 2016+
|
||||
* Version: 2016-08-15
|
||||
* Version: 2016-08-18
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -150,11 +150,13 @@ TreeGrid.prototype._setProps = function(el, props)
|
|||
|
||||
// Simple cell editing
|
||||
|
||||
TreeGrid.prototype._getCellIndex = function(n)
|
||||
TreeGrid.prototype._getCellIndex = function(n, sticky)
|
||||
{
|
||||
var i = 0;
|
||||
while ((n = n.previousSibling))
|
||||
i += (n.nodeType != 3 ? 1 : 0);
|
||||
if (sticky && this.stickyInit)
|
||||
i = (i > 0 ? i-1 : i);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -170,7 +172,7 @@ TreeGrid.prototype.initCellEditing = function()
|
|||
td = td.parentNode;
|
||||
if (td.nodeName == 'TD' && td.parentNode._node && td.previousSibling && td.className != 'celleditor')
|
||||
{
|
||||
var params = self.onStartCellEdit && self.onStartCellEdit(td.parentNode._node, self._getCellIndex(td), td) || {};
|
||||
var params = self.onStartCellEdit && self.onStartCellEdit(td.parentNode._node, self._getCellIndex(td, true), td) || {};
|
||||
if (params.abort)
|
||||
return;
|
||||
self.editedCells.push(td);
|
||||
|
@ -203,7 +205,7 @@ TreeGrid.prototype.initCellEditing = function()
|
|||
|
||||
TreeGrid.prototype.stopCellEditing = function(td, _int)
|
||||
{
|
||||
var i = this._getCellIndex(td);
|
||||
var i = this._getCellIndex(td, true);
|
||||
var node = td.parentNode._node;
|
||||
node._oldCells[i] = undefined;
|
||||
var params = this.onStopCellEdit && this.onStopCellEdit(node, i, td.firstChild ? td.firstChild.value : null, td) || {};
|
||||
|
@ -234,14 +236,14 @@ TreeGrid.prototype.initCellSelection = function(restrictToNode)
|
|||
{
|
||||
if (!cell.parentNode._node || cell.className.indexOf(' selected') >= 0)
|
||||
return;
|
||||
var i = self._getCellIndex(cell);
|
||||
var i = self._getCellIndex(cell, true);
|
||||
if (!self.onCellSelect || self.onCellSelect(cell.parentNode._node, i, cell))
|
||||
cell.className += ' selected';
|
||||
};
|
||||
|
||||
self.deselectCell = function(cell)
|
||||
{
|
||||
self.onCellDeselect && self.onCellDeselect(cell.parentNode._node, self._getCellIndex(cell), cell);
|
||||
self.onCellDeselect && self.onCellDeselect(cell.parentNode._node, self._getCellIndex(cell, true), cell);
|
||||
cell.className = cell.className.replace(' selected', '');
|
||||
};
|
||||
|
||||
|
@ -468,7 +470,8 @@ TreeGridNode.prototype._hashEqual = function(a, b)
|
|||
|
||||
TreeGridNode.prototype._renderCell = function(i, cell)
|
||||
{
|
||||
var ri = this.stickyInit ? (i > 0 ? i+1 : 0) : i;
|
||||
// this may be the first render of a row inside a stickyheaders grid
|
||||
var ri = this.tr.cells.length && this.tr.cells[0].className.indexOf(' _scri') >= 0 ? (i > 0 ? i+1 : 0) : i;
|
||||
if (!this.tr.cells[ri])
|
||||
this.tr.appendChild(document.createElement('td'));
|
||||
// virtualDOM-like approach: compare old HTML properties
|
||||
|
|
Loading…
Reference in New Issue