I want to populate a jqGrid cell dropdownlist when I click the row. I am clicking the row but the dropdownlist isn't getting populated.
The code which I have written for populating the dropdownlist on edit or clicking the row is:
colModel: [
{ name: 'Emp_code', width: 50, sortable: false, align: "center" },
{ name: 'Emp_name', width: 200, sortable: false },
//{ name: 'totalhours', width: 100, sortable: false, align: 'center', editable: true, edittype: "select", editoptions: { value: "1:1;2:2;3:3;4:4;5:5;6:6;7:7;8:8;9:9"} }
{name: 'totalhours', index: 'totalhours', width: 100, sortable: false, align: 'center', editable: true, edittype: "select",
editoptions:
{
dataInit: function(elem) {
$(elem).empty()
.append($('<option></option>').val("1").html("Apples"))
.append($('<option></option>').val("2").html("Oranges"));
}
}
}
],
I want to populate the totalhours column on row click which would populate with apple and oranges, but somehow I am getting blank dropdowns. On row click the dropdown is shown but it's not populated.
If you need to get options item of select from the server you should use editoptions
dataUrl
and optionallybuildSelect
. If the server return JSON instead of HTML fragment likeone can use
buildSelect
to convert the server response to the format. If the srever return JSON formatted string your implementation ofbuildSelect
event handler can convert JSON string to the object and then construct the string<select>...</select>
from the object.You can find the corresponding code example for example here.