[英]JQGRID inline dropdown binding via AJAX
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. 这是我的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. 每个建议将不胜感激。
The format is wrong. 格式错误。 It should be: 它应该是:
<select><option value=“1”>One</option> <option value=“2”>Two</option></select>
Check http://www.trirand.com/jqgridwiki/doku.php?id=wiki:search_config (dataUrl). 检查http://www.trirand.com/jqgridwiki/doku.php?id=wiki:search_config(dataUrl )。
Here is a working example. 这是一个工作示例。 The info is taken from the database and then formatted in the corresponding Controller action. 该信息从数据库中获取,然后在相应的Controller操作中格式化。
<th role="columnheader" class="ui-state-default ui-th-column ui-th-ltr">
<div style="width:100%;position:relative;height:100%;padding-right:0.3em;">
<select name="TypeCode" id="gs_TypeCode" style="width: 100%; ">
<option></option>
<option value="1">cosas!</option>
<option value="2">mascosas</option>
<option value="3">yast</option>
<option value="4">tiparraco</option>
</select>
</div>
</th>
Sorry for the crappy format but I cannot post images... Hope it helps. 对不起,格式糟糕,但我无法发布图片...希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.