0

我是 jqGrid 的新手,想用来自服务器端的动态值填充 jqGrid 选择(下拉)。

服务器端方法:

public void getComponentListDetails() throws IOException {

    List<PkiComponentLicenceDetials> gridModels = getComponentList();

    JSONObject responcedata = new JSONObject();
    JSONArray cell = new JSONArray();
    int i = 1;

    try {
        for (PkiComponentLicenceDetials object : gridModels) {

            PkiComponentLicenceDetials pkiComponentLicenceDetials = (PkiComponentLicenceDetials) object;

            JSONObject cellobj = new JSONObject();

            cellobj.put("componentId", pkiComponentLicenceDetials.getComponentId());
            cellobj.put("componentName", pkiComponentLicenceDetials.getComponentName());               

            cell.add(cellobj);
            System.out.println("cell object : " + i + ": " + cellobj);
            i++;

        }
        responcedata.put("data", cell);
        System.out.println("test --- : " + responcedata);
        response.setContentType("application/json");
        response.getWriter().write(responcedata.toString());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

JSP:

        jQuery(document).ready(function(){
            jQuery("#list").jqGrid({
                url:'IssueSolutionDetails_json',
                datatype: 'json',
                mtype: 'GET',
                width:"1000",
                colNames:[ 'Id','Auto Id','Component Name','Issue Name','Issue  Description','Issue Status','Solution Provided','Provided By','Remarks'],
                colModel :[
                    {name:'columnId', index:'columnId', width:20},
                    {name:'isdAutoId', index:'isdAutoId', width:90,editable:true,hidden:true,editrules:{edithidden:false},key:true},
                    {name:'componentName', index:'componentName', width:90,editable:true,edittype:"select",editrules:{required:true},
//                                editoptions:{value:'IssueSolutionDetails_componentList'}
                        editoptions:{
                            dataUrl:'IssueSolutionDetails_getComponentListDetails',
                            buildSelect: function (response) {
                                var data = typeof response === "string" ?
                                    $.parseJSON(response.responseText) : response,
                                s = "<select>";

                                s += '<option value="0">--Select One--</option>';
                                $.each(data, function (){
                                    s += '<option value="' + this.componentId + '">' + this.componentName +
                                        '</option>';
                                });
                                return s + "</select>";
                            }
                        }
                    },
                    {name:'issueName', index:'issueName', width:90,editable:true,editrules:{required:true}},
                    {name:'issueDescription', index:'issueDescription', width:80, editable:true,editrules:{required:true}},
                    {name:'status', index:'status', width:80,editable:true,edittype:"select",editoptions:{value:"0:--Select One--;Open:Open;Close:Close;In Progress:In Progress"},editrules:{required:true,custom:true,custom_func:checkStatus}},
                    {name:'solutionProvided', index:'solutionProvided', width:80,editable:true,editrules:{required:true}},
                    {name:'providedBy', index:'providedBy', width:80,editable:true,editrules:{required:true}},
                    {name:'remarks', index:'remarks', width:80, editable:true}
                ],
                pager: '#pager',
                rowNum:10,
                rowList:[10,20,30],
                sortname: 'id',
                sortorder: 'desc',
                viewrecords: true,
                caption: 'Issue Details',
                editurl:"IssueSolutionDetails_addNewRow",
4

0 回答 0