ParamQuery grid support forum
General Category => Help for ParamQuery Select => Topic started by: lackofabettername on April 03, 2015, 11:49:04 pm
-
Hi there,
I am using pqselect in a project where when you load a user it should show the previous selected items when you first created the user. The element is of a multi select type. Also even for single select items, how can we initialize this with the default values or something?
I hope this is clear enough. I'd appreciated any help.
Thanks.
-
Hi
Setting the default options <option> in select list is simple, just add selected attributes to those options.
http://jsfiddle.net/dLvx6u63/3/
-
But what about when the pqgrid editor options are coming from a JSON array? The following does NOT work: { "value" : theValue, "text" : theText, "selected" : "selected" } or this { "value" : theValue, "text" : theText, "selected" : "true" }.
Or is the only way to handle this to override the column editor Type callback function? e.g. $( ".selector" ).pqGrid( "option", "colModel" )[6].editor.type
To answer my own question, I was able to solve it with the following, but it would be a plus to have it accept a JSON marker:
type: function (ui) {
var str = "<select multiple>",
options = ui.column.editor.options;
if (ui.cellData) {
$(options).each(function (i, option) {
var selected = '';
if (ui.cellData.indexOf(option.value) > -1) {
selected = 'selected';
}
str += "<option value='" + option.value + "' " + selected + " >" + option.text + "</option>";
});
str += "</select>"
ui.$cell.append(str);
} else {
return 'select';
}
},
-
The key name is pq_selected.
{ "value" : theValue, "text" : theText, "pq_selected" : true } or this { "value" : theValue, "text" : theText, pq_selected : true }.
Hope it helps.