Assuming you mean that you do not want to have to write 50 separate “if” statements as in @aleksandra_budnik’s JSFiddle, it’s really not hard to factor the code neatly to make it handle lots of cases. For example:
var colors = {
yellow: 10,
red: 20,
orange: 30,
...
};
var color = changes[0][3];
output.innerHTML = colors[color];
That’s it! And if your color names/values or whatever are in a database you can just look it up there instead of needing the literal “colors” values enumeration.
So, for example, let’s assume you have database rows which have a name column for the color names and a value column for the corresponding number-value. Then instead of hard-coding you can dynamically create the colors object I’m using with something like:
var colors = {};
foreach row in data-table do
colors[ row[name] ] = row[value];
end
And furthermore, to get the array of color names you need to pass as source: to the Handsontable constructor, you can just use Object.keys(colors).
Of course, assuming you will do this population at Handsontable creation-time, you will need to use colors as a “global variable” so that it is preserved for use later in the afterChange callback. You could save it as a (user-defined/extra) property on your Handsontable instance so that it is easily accessible in the right place.
Thanks Jon, but need to create two type of array, one for pass the value into the dropdown and another one for after selected from dropdown get the value.
@kiruba
I know you need a pair of values, one for the what appears in the dropdown (output) and another for what is returned (input). In my solution, the colors object is in effect an array indexed by color name (output, text in your example) whose value is the number (input, id in your example). Or you could swap them around.
I have not used a custom renderer in Hot, preferring to use the inbuilt facilities. But if the solution you have found works for you that is great.