BInd keyboard events on wrapper
This commit is contained in:
parent
cd154f4a27
commit
d89f37481f
34
index.html
34
index.html
File diff suppressed because one or more lines are too long
@ -879,10 +879,10 @@ var CellManager = function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_dom2.default.on(document.body, 'click', function (e) {
|
// $.on(document.body, 'click', e => {
|
||||||
if (e.target.matches('.edit-cell, .edit-cell *')) return;
|
// if (e.target.matches('.edit-cell, .edit-cell *')) return;
|
||||||
_this.deactivateEditing();
|
// this.deactivateEditing();
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'bindKeyboardNav',
|
key: 'bindKeyboardNav',
|
||||||
@ -1275,9 +1275,9 @@ var CellManager = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'getEditingObject',
|
key: 'getEditingObject',
|
||||||
value: function getEditingObject(colIndex, rowIndex, value, parent) {
|
value: function getEditingObject(colIndex, rowIndex, value, parent) {
|
||||||
if (this.options.editing) {
|
// debugger;
|
||||||
return this.options.editing(colIndex, rowIndex, value, parent);
|
var obj = this.options.editing(colIndex, rowIndex, value, parent);
|
||||||
}
|
if (obj && obj.setValue) return obj;
|
||||||
|
|
||||||
// editing fallback
|
// editing fallback
|
||||||
var $input = _dom2.default.create('input', {
|
var $input = _dom2.default.create('input', {
|
||||||
@ -1317,6 +1317,7 @@ var CellManager = function () {
|
|||||||
|
|
||||||
// update cell immediately
|
// update cell immediately
|
||||||
this.updateCell(colIndex, rowIndex, value);
|
this.updateCell(colIndex, rowIndex, value);
|
||||||
|
$cell.focus();
|
||||||
|
|
||||||
if (done && done.then) {
|
if (done && done.then) {
|
||||||
// revert to oldValue if promise fails
|
// revert to oldValue if promise fails
|
||||||
@ -1430,22 +1431,22 @@ var CellManager = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'getLeftMostCell$',
|
key: 'getLeftMostCell$',
|
||||||
value: function getLeftMostCell$(rowIndex) {
|
value: function getLeftMostCell$(rowIndex) {
|
||||||
return this.getCell$(rowIndex, this.columnmanager.getFirstColumnIndex());
|
return this.getCell$(this.columnmanager.getFirstColumnIndex(), rowIndex);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getRightMostCell$',
|
key: 'getRightMostCell$',
|
||||||
value: function getRightMostCell$(rowIndex) {
|
value: function getRightMostCell$(rowIndex) {
|
||||||
return this.getCell$(rowIndex, this.columnmanager.getLastColumnIndex());
|
return this.getCell$(this.columnmanager.getLastColumnIndex(), rowIndex);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getTopMostCell$',
|
key: 'getTopMostCell$',
|
||||||
value: function getTopMostCell$(colIndex) {
|
value: function getTopMostCell$(colIndex) {
|
||||||
return this.getCell$(this.rowmanager.getFirstRowIndex(), colIndex);
|
return this.getCell$(colIndex, this.rowmanager.getFirstRowIndex());
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getBottomMostCell$',
|
key: 'getBottomMostCell$',
|
||||||
value: function getBottomMostCell$(colIndex) {
|
value: function getBottomMostCell$(colIndex) {
|
||||||
return this.getCell$(this.rowmanager.getLastRowIndex(), colIndex);
|
return this.getCell$(colIndex, this.rowmanager.getLastRowIndex());
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getCell',
|
key: 'getCell',
|
||||||
@ -1465,12 +1466,13 @@ var CellManager = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'scrollToCell',
|
key: 'scrollToCell',
|
||||||
value: function scrollToCell($cell) {
|
value: function scrollToCell($cell) {
|
||||||
if (_dom2.default.inViewport($cell, this.bodyScrollable)) return;
|
if (_dom2.default.inViewport($cell, this.bodyScrollable)) return false;
|
||||||
|
|
||||||
var _$$data12 = _dom2.default.data($cell),
|
var _$$data12 = _dom2.default.data($cell),
|
||||||
rowIndex = _$$data12.rowIndex;
|
rowIndex = _$$data12.rowIndex;
|
||||||
|
|
||||||
this.rowmanager.scrollToRow(rowIndex);
|
this.rowmanager.scrollToRow(rowIndex);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'getRowCountPerPage',
|
key: 'getRowCountPerPage',
|
||||||
@ -1494,7 +1496,7 @@ function getCellHTML(column) {
|
|||||||
isHeader: isHeader
|
isHeader: isHeader
|
||||||
});
|
});
|
||||||
|
|
||||||
return '\n <td class="data-table-col noselect" ' + dataAttr + '>\n ' + getCellContent(column) + '\n </td>\n ';
|
return '\n <td class="data-table-col noselect" ' + dataAttr + ' tabindex="0">\n ' + getCellContent(column) + '\n </td>\n ';
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCellContent(column) {
|
function getCellContent(column) {
|
||||||
@ -2187,6 +2189,10 @@ var _style = __webpack_require__(12);
|
|||||||
|
|
||||||
var _style2 = _interopRequireDefault(_style);
|
var _style2 = _interopRequireDefault(_style);
|
||||||
|
|
||||||
|
var _keyboard = __webpack_require__(8);
|
||||||
|
|
||||||
|
var _keyboard2 = _interopRequireDefault(_keyboard);
|
||||||
|
|
||||||
var _defaults = __webpack_require__(13);
|
var _defaults = __webpack_require__(13);
|
||||||
|
|
||||||
var _defaults2 = _interopRequireDefault(_defaults);
|
var _defaults2 = _interopRequireDefault(_defaults);
|
||||||
@ -2227,6 +2233,8 @@ var DataTable = function () {
|
|||||||
this.cellmanager = new _cellmanager2.default(this);
|
this.cellmanager = new _cellmanager2.default(this);
|
||||||
this.bodyRenderer = new _bodyRenderer2.default(this);
|
this.bodyRenderer = new _bodyRenderer2.default(this);
|
||||||
|
|
||||||
|
_keyboard2.default.init(this.wrapper);
|
||||||
|
|
||||||
if (this.options.data) {
|
if (this.options.data) {
|
||||||
this.refresh(this.options.data);
|
this.refresh(this.options.data);
|
||||||
}
|
}
|
||||||
@ -2972,10 +2980,13 @@ var KEYCODES = {
|
|||||||
67: 'c'
|
67: 'c'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var initDone = false;
|
||||||
var handlers = {};
|
var handlers = {};
|
||||||
|
|
||||||
function bind() {
|
function bind(dom) {
|
||||||
_dom2.default.on(document, 'keydown', handler);
|
if (initDone) return;
|
||||||
|
_dom2.default.on(dom, 'keydown', handler);
|
||||||
|
initDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handler(e) {
|
function handler(e) {
|
||||||
@ -3002,9 +3013,10 @@ function handler(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bind();
|
|
||||||
|
|
||||||
exports.default = {
|
exports.default = {
|
||||||
|
init: function init(dom) {
|
||||||
|
bind(dom);
|
||||||
|
},
|
||||||
on: function on(key, handler) {
|
on: function on(key, handler) {
|
||||||
var keys = key.split(',').map(function (k) {
|
var keys = key.split(',').map(function (k) {
|
||||||
return k.trim();
|
return k.trim();
|
||||||
@ -3298,7 +3310,7 @@ exports.default = {
|
|||||||
none: ''
|
none: ''
|
||||||
},
|
},
|
||||||
freezeMessage: 'Loading...',
|
freezeMessage: 'Loading...',
|
||||||
editing: null,
|
editing: function editing() {},
|
||||||
addSerialNoColumn: true,
|
addSerialNoColumn: true,
|
||||||
addCheckboxColumn: true,
|
addCheckboxColumn: true,
|
||||||
enableClusterize: true,
|
enableClusterize: true,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -51,10 +51,10 @@ export default class CellManager {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.on(document.body, 'click', e => {
|
// $.on(document.body, 'click', e => {
|
||||||
if (e.target.matches('.edit-cell, .edit-cell *')) return;
|
// if (e.target.matches('.edit-cell, .edit-cell *')) return;
|
||||||
this.deactivateEditing();
|
// this.deactivateEditing();
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
bindKeyboardNav() {
|
bindKeyboardNav() {
|
||||||
@ -374,9 +374,9 @@ export default class CellManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getEditingObject(colIndex, rowIndex, value, parent) {
|
getEditingObject(colIndex, rowIndex, value, parent) {
|
||||||
if (this.options.editing) {
|
// debugger;
|
||||||
return this.options.editing(colIndex, rowIndex, value, parent);
|
const obj = this.options.editing(colIndex, rowIndex, value, parent);
|
||||||
}
|
if (obj && obj.setValue) return obj;
|
||||||
|
|
||||||
// editing fallback
|
// editing fallback
|
||||||
const $input = $.create('input', {
|
const $input = $.create('input', {
|
||||||
@ -411,6 +411,7 @@ export default class CellManager {
|
|||||||
|
|
||||||
// update cell immediately
|
// update cell immediately
|
||||||
this.updateCell(colIndex, rowIndex, value);
|
this.updateCell(colIndex, rowIndex, value);
|
||||||
|
$cell.focus();
|
||||||
|
|
||||||
if (done && done.then) {
|
if (done && done.then) {
|
||||||
// revert to oldValue if promise fails
|
// revert to oldValue if promise fails
|
||||||
@ -501,19 +502,19 @@ export default class CellManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getLeftMostCell$(rowIndex) {
|
getLeftMostCell$(rowIndex) {
|
||||||
return this.getCell$(rowIndex, this.columnmanager.getFirstColumnIndex());
|
return this.getCell$(this.columnmanager.getFirstColumnIndex(), rowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRightMostCell$(rowIndex) {
|
getRightMostCell$(rowIndex) {
|
||||||
return this.getCell$(rowIndex, this.columnmanager.getLastColumnIndex());
|
return this.getCell$(this.columnmanager.getLastColumnIndex(), rowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTopMostCell$(colIndex) {
|
getTopMostCell$(colIndex) {
|
||||||
return this.getCell$(this.rowmanager.getFirstRowIndex(), colIndex);
|
return this.getCell$(colIndex, this.rowmanager.getFirstRowIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
getBottomMostCell$(colIndex) {
|
getBottomMostCell$(colIndex) {
|
||||||
return this.getCell$(this.rowmanager.getLastRowIndex(), colIndex);
|
return this.getCell$(colIndex, this.rowmanager.getLastRowIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
getCell(colIndex, rowIndex) {
|
getCell(colIndex, rowIndex) {
|
||||||
@ -529,11 +530,11 @@ export default class CellManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scrollToCell($cell) {
|
scrollToCell($cell) {
|
||||||
if ($.inViewport($cell, this.bodyScrollable)) return;
|
if ($.inViewport($cell, this.bodyScrollable)) return false;
|
||||||
|
|
||||||
const { rowIndex } = $.data($cell);
|
const { rowIndex } = $.data($cell);
|
||||||
|
|
||||||
this.rowmanager.scrollToRow(rowIndex);
|
this.rowmanager.scrollToRow(rowIndex);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRowCountPerPage() {
|
getRowCountPerPage() {
|
||||||
@ -550,7 +551,7 @@ export function getCellHTML(column) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<td class="data-table-col noselect" ${dataAttr}>
|
<td class="data-table-col noselect" ${dataAttr} tabindex="0">
|
||||||
${getCellContent(column)}
|
${getCellContent(column)}
|
||||||
</td>
|
</td>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import ColumnManager from './columnmanager';
|
|||||||
import RowManager from './rowmanager';
|
import RowManager from './rowmanager';
|
||||||
import BodyRenderer from './body-renderer';
|
import BodyRenderer from './body-renderer';
|
||||||
import Style from './style';
|
import Style from './style';
|
||||||
|
import keyboard from './keyboard';
|
||||||
import DEFAULT_OPTIONS from './defaults';
|
import DEFAULT_OPTIONS from './defaults';
|
||||||
import './style.scss';
|
import './style.scss';
|
||||||
|
|
||||||
@ -40,6 +41,8 @@ class DataTable {
|
|||||||
this.cellmanager = new CellManager(this);
|
this.cellmanager = new CellManager(this);
|
||||||
this.bodyRenderer = new BodyRenderer(this);
|
this.bodyRenderer = new BodyRenderer(this);
|
||||||
|
|
||||||
|
keyboard.init(this.wrapper);
|
||||||
|
|
||||||
if (this.options.data) {
|
if (this.options.data) {
|
||||||
this.refresh(this.options.data);
|
this.refresh(this.options.data);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,7 +41,7 @@ export default {
|
|||||||
none: ''
|
none: ''
|
||||||
},
|
},
|
||||||
freezeMessage: 'Loading...',
|
freezeMessage: 'Loading...',
|
||||||
editing: null,
|
editing: () => {},
|
||||||
addSerialNoColumn: true,
|
addSerialNoColumn: true,
|
||||||
addCheckboxColumn: true,
|
addCheckboxColumn: true,
|
||||||
enableClusterize: true,
|
enableClusterize: true,
|
||||||
|
|||||||
@ -15,10 +15,13 @@ const KEYCODES = {
|
|||||||
67: 'c'
|
67: 'c'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let initDone = false;
|
||||||
const handlers = {};
|
const handlers = {};
|
||||||
|
|
||||||
function bind() {
|
function bind(dom) {
|
||||||
$.on(document, 'keydown', handler);
|
if (initDone) return;
|
||||||
|
$.on(dom, 'keydown', handler);
|
||||||
|
initDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handler(e) {
|
function handler(e) {
|
||||||
@ -45,9 +48,10 @@ function handler(e) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bind();
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
init(dom) {
|
||||||
|
bind(dom);
|
||||||
|
},
|
||||||
on(key, handler) {
|
on(key, handler) {
|
||||||
const keys = key.split(',').map(k => k.trim());
|
const keys = key.split(',').map(k => k.trim());
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user