[英]How can I set the selected index of a comboBox base from its valueMember? (C# Window Form)
[英]How can i set the selected index with data from server to a combobox in a jqgrid
我有一个带有带组合框(选择)的列的jqgrid,并且我通过返回所需选项的函数在editoptions中设置了值。
我的问题是如何将保存的值带到那里:
例如:我的选项是:1:是,2:否,3:也许
从服务器上,客户端保存了选项2,我想在jqgrid中显示NO。
这是我的一些代码:
function getAllSelectOptions() {
var state= {
'1': 'yes', '2': 'no',
'3': 'maybe' };
return state;
}
function formatTest(cellvalue, options, rowObject) {
$.ajax({
type: "POST",
url: "Customers.aspx/getOptions",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function(result) {
//return options.colModel.editoptions.value[result.d]; shows me the value from server, but i cant return it.
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + ": " + XMLHttpRequest.responseText);
}
});
}
//combo
{
name: 'column1', index: 'column1', width: 23,
align: 'center',
editable: true,
edittype: 'select',
formatter: formatTest,
editoptions: {value: getAllSelectOptions()}
}
您没有发布有关操作的足够详细信息,但是我想在该列中添加formatter: "select"
应该可以解决问题。 在格式化程序中使用异步调用是绝对错误的方式。 如果您已经设置了editoptions.value
那么formatter: "select"
将使用该信息并将输入数据1、2和3解码为文本'yes'
, 'no'
或'maybe'
,这些文本将显示在相应的列的网格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.