ce
ce copied to clipboard
Open dropdown when down arrow is pressed and close when the tab key is pressed
Currently the only way the user can open the dropdown is by double clicking
At the moment I have tried this in a jexcel table with multiple sheets, the dropdown is opened with the down arrow key and closed with the tab key but does not save the selected value
document.getElementById('spreadsheet').onkeydown = e => {
if (e.code == 'ArrowDown') {
let cell = document.querySelector('.jexcel_dropdown.highlight-selected');
let instances = document.querySelectorAll('.jexcel_container');
let currentInstance = Array.from(instances).find(c => c.style.display != 'none');
let dropdownHasFocus = document.querySelector('.jdropdown-focus');
if (cell && currentInstance && !dropdownHasFocus) {
currentInstance.jexcel.openEditor(cell);
}
} else if (e.code == 'Tab') {
let cell = document.querySelector('.jexcel_dropdown.highlight-selected');
let instances = document.querySelectorAll('.jexcel_container');
let currentInstance = Array.from(instances).find(c => c.style.display != 'none');
let dropdownHasFocus = document.querySelector('.jdropdown-focus');
if (cell && currentInstance && dropdownHasFocus) {
currentInstance.jexcel.closeEditor(cell);
// prevent lost focus
currentInstance.focus();
}
}
};
I was able to save the data, calling close on the dropdown instead of closeEditor on the cell
document.getElementById('spreadsheet').onkeydown = e => {
if (e.code == 'ArrowDown') {
let cell = document.querySelector('.jexcel_dropdown.highlight-selected');
let instances = document.querySelectorAll('.jexcel_container');
let currentInstance = Array.from(instances).find(c => c.style.display != 'none');
let dropdownHasFocus = document.querySelector('.jdropdown-focus');
if (cell && currentInstance && !dropdownHasFocus) {
currentInstance.jexcel.openEditor(cell);
}
} else if (e.code == 'Tab') {
let cell = document.querySelector('.jexcel_dropdown.highlight-selected');
let instances = document.querySelectorAll('.jexcel_container');
let currentInstance = Array.from(instances).find(c => c.style.display != 'none');
let currentDropdown = document.querySelector('.jdropdown-focus');
if (cell && currentInstance && currentDropdown) {
currentDropdown.dropdown.close();
// prevent lost focus
currentInstance.focus();
}
}
};
Alternatively, you can create a button and call openEditor to start the edition of one specific cell.
I have idea.
onselection: function (instance, x1, y1, x2, y2, origin) {
if (x1 == 2) {
var columnName = jexcel.getColumnNameFromId([x1, y1]);
var cell = instance.jexcel.getCell(columnName);
instance.jexcel.openEditor(cell);
cell.children[0].dropdown.close(true);
}
},
User can open dropdown by single clicking.