JQGRID inline dropdown binding via AJAX
- by Frank
jQuery(document).ready(function () {
var grid = $("#list");
var AllCategory={"1":"Computing","2":"Cooking","10":"Fiction","3":"Finance","6":"Language","4":"Medical","11":"News","8":"Philosophy","9":"Religion","7":"Sport","5":"Travel"};
grid.jqGrid({
url: '/SupplierOrder/Select_SupplierOrderDetailByX/',
editurl: "clientArray",
datatype: 'json',
mtype: 'GET',
colNames: ['Category', 'Qty'],
colModel: [
{
name: 'Category', index: 'CategoryID', align: 'left', editable: true, edittype: "select", formatter: 'select',
editoptions: { value: AllCategory }, editrules: { required: true }
},
{ name: 'Qty', index: 'Qty', width: 40, align: 'left', editable: true, edittype: "text", editoptions: { size: "35", maxlength: "50"} }
],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [5, 10, 20, 50],
sortname: '',
sortorder: '',
viewrecords: true,
autowidth: true,
autoheight: true,
imgpath: '/scripts/themes/black-tie/images',
caption: 'Supplier Order Detail'
})
grid.jqGrid('navGrid', '#pager', { edit: false, add: false, del: true, refresh: false, search: false }, {}, {}, {}, {});
grid.jqGrid('inlineNav', '#pager', {
addtext: "Add",
edittext: "Edit",
savetext: "Save",
canceltext: "Cancel"
});
});
It is my JQGrid.
Then, I remove below code ...
var AllCategory={"1":"Computing","2":"Cooking","10":"Fiction","3":"Finance","6":"Language","4":"Medical","11":"News","8":"Philosophy","9":"Religion","7":"Sport","5":"Travel"};
Replace with below code so that i can get dynamic data ...
var AllCategory = (function () {
var list = null;
$.ajax({
async: false,
global: false,
type: "POST",
url: 'Category_Lookup',
dataType: 'json',
data: {},
success: function (response, textStatus, jqXHR) {
list = response;
},
error: function (jqXHR, textStatus, errorThrown) {
alert("jqXHR.responseText --> " + jqXHR.responseText + "\njqXHR --> " + jqXHR + "\ntextStatus --> " + textStatus + " \nerrorThrown --> " + errorThrown);
}
});
alert(list);
return list;
})();
Firstly, I get below message box ...
Then I get Error
Could anyone please tell me how to make it correct ?
Every suggestion will be appreciated.