I’m using a modified version of the [Ref: Handsontable example - JSFiddle - Code Playground].
Requirement
I want to:
- Display a dropdown in a cell using the custom
key-value-list
type. - Show a button inside the cell (e.g., “Show All”).
- When clicked, the button should:
- Fetch a new list of key-value pairs asynchronously.
- Replace the existing dropdown options (
source
) with the new list dynamically.
UpdateSettings
spreadsheet.updateSettings({
cells: function (row, col, prop) {
const rowData = this.instance.getSourceDataAtRow(row);
if (prop === 'cutom_field') {
return {
type: 'key-value-list',
source: rowData._cutom_field_data || [],
customSuffixButton: {
label: 'Show All',
onClickCallback: ({ row, col, hot }) => {
// Simulated async call
fetchAllOptions(function (responseData) {
const allOptions = responseData.data;
// Update source of the dropdown dynamically
hot.setCellMeta(row, col, 'source', allOptions);
hot.render();
});
}
}
};
}
}
});
CustomRenderer
const config = cellProperties.customSuffixButton;
if (config) {
const btn = document.createElement('button');
// Label
btn.textContent = config.label || 'Action';
btn.className = 'btn btn-sm btn-primary';
// Style
btn.style.float = 'right';
btn.style.marginLeft = '8px';
btn.style.padding = '2px 6px';
btn.style.fontSize = '12px';
// Callback
btn.onclick = function () {
config.onClickCallback({
row,
col,
prop,
hot,
cellProperties
});
};
TD.appendChild(btn);
}
Problem
- The button appears correctly, and the callback is fired.
- However, the dropdown does not reflect the new list, and the UI continues to show the old options.