jqGrid在行编辑中填充选择控件 [英] jqGrid populate select control on row edit
问题描述
我想将xml文件中的约150个元素添加到jqGrid单元格内的选择控件.我正在考虑通过两种方式做到这一点:
I want to add about 150 element from a xml file to a select control that is inside a jqGrid cell. I was thinking of doing this in two ways:
1.使用editoptions值:
1.Using the editoptions value:
{ name: 'language', width: 100, sortable: false, editable: true, edittype: 'select', editoptions: { value: languageElem()} }
使用从方法接收的数据:
using data received from the method:
function languageElem() {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'jqService.asmx/GetLanguages',
data: {},
dataType: "json",
success: function (data) {
alert("success");
}
});}
但是我无法从ajax部分转发数据.
But I'm having trouble forwarding the data from the ajax part.
2.只需访问jqGrid单元格内的select控件,并在按下编辑按钮时手动添加选项.
2.Simply accessing the select control inside the jqGrid cell and manually adding the options whenever the edit button is pressed.
这里的问题是我不知道如何访问控件本身.
The problem over here is that I have no idea how to access the control itself.
我在这里使用的代码是:
The code I used over here is:
function startEdit() {
if (selRow > -1) {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'jqService.asmx/GetLanguages',
data: {},
dataType: "json",
success: function (data) {
var cell = jQuery("#MainContent_list").getCell(selRow, "language");
cell.options.length = 0;
for (var i=0;i<data.d.length;i++)
{
}
}
});
jQuery("#MainContent_list").jqGrid('restoreRow', selRow);
jQuery("#MainContent_list").jqGrid('editRow', selRow);
}
我的问题是:
1.关于第一个想法,我应该怎么做才能修复该方法,以便控件可以接收它的所需值?
1.Related to the first idea, what should I do to fix the method so that the control will receive it's needed values?
2.关于第二个想法,我如何访问行内的控件?
2.Related to the second idea, how could I access the control inside the row?
谢谢,卡塔琳
推荐答案
而不是value
属性(editoptions: { value: languageElem()}
),您应该使用dataUrl
和buildSelect
(请参阅答案,并在此您将找到其他信息.如果您要搜索dataUrl
和buildSelect
,则会找到更多信息和可以使用的代码示例.
Instead of value
property (editoptions: { value: languageElem()}
) you should use dataUrl
and buildSelect
(see the documentation). Because it's difficult to return from ASMX HTML fragment <select><option>...</option></select>
you can provide the list serialized as JSON and convert the server response to HTML fragment using buildSelect
. In the answer and in this one you will find additional information. If you would search for dataUrl
and buildSelect
you will find more information and code example which you could use.
这篇关于jqGrid在行编辑中填充选择控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!