I’m trying to build off the previously asked question from the link reference below. Ultimately, I’m trying to source my dropdown from a SQL database which returns the data in a JSON string. I know it was stated that 1) “you cannot use JSON” as the dropdown source, 2) “the dropdown cell type has to be passed with an array of options”, and 3) I’d need to parse the JSON to do that.
However, do you have a suggestion on how I might do parse the JSON to an array of options?
Sorry if this is a simple question or should be asked elsewhere, but I quite a bit of searching and attempts, I cannot seem to find a straight example.
The key part of the code below is “var vMYDATA = MyRespnse.d” variable which returns the following JSON from the SQL server response.
[{"Size":"small"},{"Size":"medium"},{"Size":"large"}]
However, I assume it needs to be converted as the below to work with the dropdown. Is there a javascript or jquery function that does that? Or do I need to build something on my own?
["small", "medium", "large"]
Code:
const MyContainer = document.querySelector('#MyExample');
const MyHOT = new Handsontable(MyContainer, {
data: [
['Shirt', 'medium'],
['Pants', 'large'],
['Shorts', 'small']
],
colHeaders: ['Clothes', 'Size'],
columns: [
{},
{
type: 'dropdown',
source(query, process) {
$.ajax({
type: "POST",
url: "myexample.aspx/LoadSqlServerJson",
data: '{MyRecordID: "true" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (MyResponse) {
var vMYDATA = MyResponse.d;
process(vMYDATA);
}
});
}
},
],
licenseKey: 'non-commercial-and-evaluation'
});
Link:
Dropdown menu with json data - Getting help / Questions - Handsontable Forum