I want to make a dynamically populated html select for a select cell. I extract some information from a database which is different for every row item. The problem is that the editor loses the initial data and I don't know how to keep some data for a specific cell. Has someone done this before?
function StandardSelectCellEditor($container, columnDef, value, dataContext) {
var $input;
var $select;
var defaultValue = value;
var scope = this;
this.init = function() {
$input = $("<INPUT type=hidden />");
$input.val(value);
}
$input.appendTo($container);
$select = $("<SELECT tabIndex='0' class='editor-yesno'>");
jQuery.each(value, function() {
$select.append("<OPTION value='" + this + "'>" + this + "</OPTION></SELECT>");
});
$select.append("</SELECT>");
$select.appendTo($container);
$select.focus();
};
this.destroy = function() {
//$input.remove();
$select.remove();
};
this.focus = function() {
$select.focus();
};
this.setValue = function(value) {
$select.val(value);
defaultValue = value;
};
this.getValue = function() {
return $select.val();
};
this.isValueChanged = function() {
return ($select.val() != defaultValue);
};
this.validate = function() {
return {
valid: true,
msg: null
};
};
this.init();
};
A similar queations was asked here (this one is however not slickgrid tagged).
I did make a SelectEditor, with a flexible range of options depending on the column we are in. The reason of thinking here is that the datatype of the value you edit in a column will determine the valid choices for this field.
In order to do this you can add an extra option to your column definitions (e.g. called options) like this:
]
and access that using args.column.options in the init method of your own SelectEditor object like this:
replace
with
if it is not working for you
Please try the below code.
In slick.editors.js,Define a new editor.
Then, modify your grid options
};
And use the editor while columns initialization.
I can't add comments yet, but I need to add something to HeiN's answer.
HeiN's answer works great, but I have data coming in that does not match my select options and I need to still display that data... so I have had to modify dataItemColumnValueExtractor in the options. This allows my original data to display if I do not have an option in the list to match.
Hope this helps somebody later down the line.
You can slightly modify the above SelectCellEditor to create different select options for each cell.
Now it is easy to create a dynamic dropdown editor.