The reason: The jqGrid SELECT element binds the selected option(s) innerHTML (not the value) with the name value in the colModel.
Example:
In the JavaScript file I have a function that I call to setup the grid:
function jqGridAccountContact(item, listURL, editURL, $rows, hideGrid) {
//get all DMRoles for the drop down box from the server as key-value pairs
var allDMRoles = $.ajax({ url: $('#ajaxAllDMRolesUrl').val(), async: false, success: function(data, result) { if (!result) alert('Failure to retrieve the DM Roles.'); } }).responseText;
$(item)
.jqGrid({
url: listURL,
datatype: "json",
colNames: ['Id', 'First Name', 'Last Name', 'DM Role'],
colModel: [
{ name: 'Id', index: 'Id', width: 35, sortable: true, align: "center", resizable: false, hidden: false, editable: false, editoptions: { readonly: true, size: 0} },
{ name: 'FirstName', index: 'FirstName', width: 40, editable: true, sortable: true, align: "left", resizable: true, hidden: true, editrules: { edithidden: true, required: true} },
{ name: 'LastName', index: 'LastName', width: 40, editable: true, sortable: true, align: "left", resizable: true, hidden: true, editrules: { edithidden: true} },
{ name: 'DMRole', index: 'DMRole', width: 30, editable: true, sortable: false, align: "center", resizable: false, edittype: "select", hidden: true, editoptions: { value: allDMRoles }, editrules: { edithidden: true, required: true} },
],
The key-value pair retrieved from the server for allDMRoles looks like this:
1:Final DM;2:Influencer;3:Blocker;4:DM Agent
jqGrid generates a SELECT element that looks like this:
It matches the value in the row of DMRole (in the colModel) with the value from allDMRoles: form example "Final DM" and not the value "1".
No comments:
Post a Comment