JSFiddle - React, Tailwind, and code Playground
HTML
<!-- 14.6.2 -->
<!-- <link href="https://cdn.jsdelivr.net/npm/handsontable@14.6.2/dist/handsontable.min.css" rel="stylesheet"> -->
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/handsontable@14.6.2/dist/handsontable.full.min.js"></script> -->
<!-- 15.0.0 -->
<!-- <link href="https://cdn.jsdelivr.net/npm/handsontable@15.0.0/dist/handsontable.min.css" rel="stylesheet"> -->
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/handsontable@15.0.0/dist/handsontable.full.min.js"></script> -->
<!-- 18.1.2 -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/handsontable@18.1.2/dist/handsontable.full.min.js"></script>
<div id="hot-container">
</div>
JavaScript
class HandsontableAjaxEditor extends Handsontable.editors.HandsontableEditor {
// Fetch and format choices when editor opens
open() {
super.open();
this.addHook('beforeKeyDown', event => this.onBeforeKeyDown(event));
this.hot._registerTimeout(() => {
this.queryChoices(this.TEXTAREA.value, true);
});
}
// Closes the editor.
close() {
this.removeHooksByKey('beforeKeyDown');
super.close();
}
// Fetch choices
queryChoices(query, initial=false) {
const source = this.cellProperties.source;
this.query = query;
query = initial ? "" : query
source.call(this.cellProperties, query, (data) => {
this.rawData = data
this.updateData(this.formatData(data))
// NOTE1: Updating width and height and refreshing dimensions in 18.1.2 makes editor slightly larger, but still not large enough
this.htEditor.updateSettings({
width: this.getTargetDropdownWidth(),
height: this.getTargetDropdownHeight(),
});
this.refreshDimensions();
this.flipDropdownVerticallyIfNeeded();
this.flipDropdownHorizontallyIfNeeded();
})
}
// Format choices
formatData(rawData) {
const propSelection = this.htOptions.colSelection
const editor = this.htEditor
let formattedData = []
for (const rawRow of rawData) {
let row = JSON.parse(JSON.stringify(rawRow))
// original value: bold whole row
if (this.originalValue && row[propSelection] == this.originalValue) {
for (const prop in row) {
if...