使用edittype select和multiple true,选择框不会加载数据

时间:2011-08-05 07:20:50

标签: jqgrid

我在jqGrid中选择了框并使用dataUrl加载数据m。一切正常,但当我将multiple作为true时,数据不会显示在网格中,而是在控制台中打印数据。谷歌搜索了很多,但找不到解决方案。

$(document).ready(function () {
    var lastsel;
    var skip = 0;
    jQuery("#list").jqGrid({
        url: 'SomeActionClass.do?option=LOAD',
        datatype: "json",
        colNames: [],
        colModel: [
            { name: 'generalised_skill_id', index: 'generalised_skill_id',
                width: 120, formoptions: { rowpos: 2, colpos: 1 },
                editable: true, edittype: "select",
                editoptions: {
                    dataEvents: [
                        {
                            type: 'change',
                            fn: function (e) {
                                var Value = $(this).val();
                                if (Value == "CreateNew") {
                                    addSkill(Value);
                                }
                            }
                        }],
                    dataUrl: 'PopulatePrimarySkillData.do?nd=' + Math.random()
                }
            },
            { name: 'primary_skill_ids', index: 'primary_skill_ids', width: 120,
                formoptions: { rowpos: 2, colpos: 2 },
                editable: true, editrules: { required: true }, edittype: "select",
                editoptions: {
                    dataEvents: [
                        {
                            type: 'change',
                            fn: function (e) {
                                var Value = $(this).val();
                                if (Value == "CreateNew") {
                                    addSkill(Value);
                                }
                            }
                        }],
                        value: "", multiple: true, size: 3,
                    dataUrl: 'PopulatePrimarySkillData.do?nd=' + Math.random()
                }
            },
        ],
        rowNum: 25,
        rowList: [25, 50, 75, 100],
        pager: '#pager',
        rowTotal: 10000,
        sortname: 'rgs_id',
        viewrecords: true,
        height: 600,
        sortorder: "asc",
        multiselect: true,
        mtype: "POST",
        gridview: true,
        ignoreCase: true,
        loadonce: true,
        loadComplete: function () {
            $('#list').setGridParam({ datatype: "json" });
            $('#list').trigger("filterToolbar");
            $('#list').trigger("reloadGrid");
        },
        ondblClickRow: function (id) {
            if (id && id !== lastsel) {
                data = jQuery('#list').getRowData(id);
                var str = data['status'];
                if (str == "Fulfilled" || str == "Canceled") {
                    alert('Fulfilled and Cancelled demands can not be edited');
                } else {
                    jQuery('#list').jqGrid('restoreRow', lastsel);
                    jQuery('#list').jqGrid('editRow', id, true, pickdates);
                    lastsel = id;
                }
            }
        },
        editurl: 'SomeActionClass.do?option=EDITorADD'
    });
});

对于广义技能,它加载选择框,但对于主要技能,它不加载任何东西。但是,如果我从主要技能中移除multiple:true,则会加载数据。

非常感谢任何帮助。

以下是我的PopulatePrimarySkillData类。

    // In this function query to fetch all the skills from database is written.
    ArrayList primarySkillList = fetchPrimarySkills();
    StringBuilder htmlSelectString = new StringBuilder("<select> ");
    for (int i = 0; i < primarySkillList.size(); i++) {
        SkillsetBean sb = (SkillsetBean) primarySkillList.get(i);
        htmlSelectString.append("<option value='");
        htmlSelectString.append(sb.getPrimarySkillId());
        htmlSelectString.append("'>");
        htmlSelectString.append(sb.getPrimarySkillDesc());
        htmlSelectString.append("</option>");
    }
    htmlSelectString
            .append("<option value='CreateNew'>Create New</option> ");
    htmlSelectString.append("</select> ");
    PrintWriter out = response.getWriter();
    System.out.println("The SELECT String is : "
            + htmlSelectString.toString());
    out.println(htmlSelectString.toString());
    return null;

此功能在控制台中打印以下结果。

 <select> <option value='1'>.Net</option>
<option value='2'>Appl packaging</option>
<option value='3'>BOXI</option>
<option value='4'>Business Analyst</option>
<option value='5'>C++</option>
<option value='6'>CNG</option>
<option value='7'>DB2</option>
<option value='8'>Flash</option>
<option value='9'>IIS Admin</option>
<option value='10'>Informatica</option>
<option value='11'>Java / J2EE</option>
<option value='12'>Java Flex</option>
<option value='13'>MS Access</option>
<option value='14'>Mainframe</option>
<option value='15'>NAT/ADABAS</option>
<option value='16'>Oracle</option>
<option value='17'>Oracle DBA</option>
<option value='18'>Others</option>
</select> 

我认为在服务器端,当我删除“multiple:true”数据时,没有问题。

以下是示例JSON数据。我希望这有用。

{"id":"166","cell":["Business Analyst","BOXI,C++"]}
{"id":"167","cell":["C++",".Net,C++"]}
{"id":"168","cell":[".Net",".Net,CNG"]}
{"id":"169","cell":["Business Analyst","Appl packaging,Business Analyst"]}
{"id":"170","cell":["Business Analyst,C++","CICS,Cobol"]}
{"id":"171","cell":[,"Appl packaging",".Net,Business Analyst"]}
{"id":"172","cell":["CNG","BOXI,Appl packaging"]}
{"id":"173","cell":["Business Analyst","Business Analyst,BOXI"]}

1 个答案:

答案 0 :(得分:4)

我遇到了一些问题(jqGrid错误),我在the answer中描述了这些问题,并将其作为the bug report发布给了jqGrid的开发人员。这些错误仍未解决,因此我尝试在Internet Explorer the demo中重现您的问题:

enter image description here

我使用IE9进行测试。如果您从

修复了jquery.jqGrid.src.js(版本4.1.2)的第8217行
if(cm[i].edittype == "select" && cm[i].editoptions.multiple===true && $.browser.msie) {

if(cm[i].edittype === "select" && typeof(cm[i].editoptions)!=="undefined" && cm[i].editoptions.multiple===true && typeof(cm[i].editoptions.dataUrl)==="undefined" && $.browser.msie) {

问题将得到解决,您将拥有

enter image description here

(请参阅the same demo,但使用固定的jquery.jqGrid.src.js)。

此外,我在评论中写道,您尝试使用

生成dataUrl中使用的唯一网址
dataUrl: 'PopulatePrimarySkillData.do?nd=' + Math.random()

生成一个网址

PopulatePrimarySkillData.do?nd=0.30184902572188804 

如果您使用dataUrl: 'PopulatePrimarySkillData.do并使用其他参数ajaxSelectOptions: { cache: false },将使用的dataUrl将非常独特,如

PopulatePrimarySkillData.do?_=1312564872215
PopulatePrimarySkillData.do?_=1312564872217 
PopulatePrimarySkillData.do?_=1312564891288
...