我有一个jqGrid,我有一些列,1列是从数据库填充的下拉列表(选择)。jqGrid切换字段从文本下拉
我想要的是:当im不在editmode列中时,只需显示必须从查询中获取的文本,并且在编辑模式下im应该显示下拉列表。
酷似这里:http://www.trirand.com/blog/jqgrid/jqgrid.html进入行编辑/输入tipyes
这里是我的网格代码:
<script type="text/javascript">
var lastsel;
$(document).ready(function() {
$.getJSON('@Url.Action("ConstructSelect")', function (data) {
setupGrid(data);
});
});
function setupGrid(data) {
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
url: '@Url.Action("GetStoreList")',
datatype: 'json',
mtype: 'GET',
colNames: ['Butiks kategori', 'Butik Navn', 'By', 'Sælger'],
colModel: [
{ name: 'Id', index: 'Id', width: 50 },
{ name: 'Butiks Kategori', index: 'StoreId', width: 200, edittype: 'text', align: 'center', editable: false },
{ name: 'Buttiks Navn', index: 'StoreName', width: 200, edittype: 'text', align: 'center', editable: false },
{ name: 'Country', index: 'Country', width: 80, sortable: true, editable: true, edittype: "select", editoptions: { value: data }}],
onSelectRow: function (id) {
if (id && id !== lastsel) {
jQuery('#list').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('editRow', id, true);
lastsel = id;
}
},
editurl: '@Url.Action("GridSave")',
rowNum: 50000,
rowList: [5, 10, 20, 50],
pager: '#page',
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
height: "500px",
imgpath: '/scripts/themes/base/images'
});
jQuery("#list").jqGrid('navGrid', "#page", { edit: false, add: false, del: false });
});
}
</script>
附:谢谢你的回答,进出口新的JQ,失误使即时制作了很多OFC,但我现在回到我原来所在之处,在下拉列表是:只要我回来家里
修订生病链接代码没有填充数据。我按照你所说的清理了代码,所以现在看起来像这样:
btw。该ConstructSelect返回一个字符串列表
jQuery(document).ready(function() {
jQuery("#list").jqGrid({
url: '@Url.Action("GetStoreList")',
ajaxSelectOptions: { type: "POST", dataType: "json" },
datatype: 'json',
mtype: 'GET',
colNames: ['Butiks kategori', 'Butik Navn', 'By', 'Sælger'],
colModel: [
{ name: 'Kategori', index: 'Kategori', width: 50, key: false},
{ name: 'Navn', index: 'Navn', align: 'center', editable: false },
{ name: 'By', index: 'By', align: 'center', editable: false },
{ name: 'Sælger', index: 'Sælger', editable: true, edittype: "select",
editoptions: { dataUrl: '@Url.Action("ConstructSelect")',
buildSelect: function (data) {
var response = jQuery.parseJSON(data.responseText);
var s = '<select>';
if (response && response.length) {
for (var i = 0, l = response.length; i < l; i++) {
var ri = response[i];
s += '<option value="' + ri + '">' + ri + '</option>';
}
}
return s + "</select>";
}
}
}],
onSelectRow: function (id) {
if (id && id !== lastsel) {
jQuery('#list').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('editRow', id, true);
lastsel = id;
}
},
editurl: '@Url.Action("GridSave")',
rowNum: 50000,
rowList: [5, 10, 20, 50],
pager: '#page',
sortname: 'Id',
sortorder: "desc",
viewrecords: true,
height: "900px"
});
jQuery("#list").jqGrid('navGrid', "#page", {edit:false, add:false, del:false});
});
好,需要稍作修改,以得到它的工作:
var response = typeof(data) === "string" ? jQuery.parseJSON(data.responseText):data;
aparently u必须告诉buildselect,美要修改的数据是字符串
但我仍然有问题,它不显示从开始哪些卖家已被选中!
好重启后mysticly工作...现在是解决
关于'typeof(data)===“string”'的问题:你是对的。我已经描述的问题[这里](http://stackoverflow.com/questions/6873242/confused-about-jquery-handling-of-my-data/6873971#6873971)。另请参阅[我的错误报告](http://www.trirand.com/blog/?page_id=393/bugs/all-usage-of-buildselect-should-be-inside-of-ajax-success/#p24174)和[修复](https://github.com/tonytomov/jqGrid/commit/baa2b502ec3478bd5cf828e5d0c6e305601276da)。在jqGrid的新版本中,'data'参数将已经是字符串数组,您不需要调用'jQuery.parseJSON'。 – Oleg