将参数从jqgrid传递给spring控制器?

时间:2012-05-21 02:26:15

标签: ajax spring-mvc

我有这个ajax代码。我也尝试了onselectrow,formatter,我想如何获取行对象并将其发送到控制器,以便我的下一页可以显示行对象发送的所有细节。

var jq = jQuery.noConflict();

jq(document).ready(function() {
    var grid = jq("#grid");
    grid.jqGrid({
        url:'${pageContext.request.contextPath}/getRegisteredClassesData.html',
        datatype: 'json',
        mtype: 'POST', 
        colNames:['Course Name'],
        colModel:[{name:'courseName',index:'courseName', width:55, 
                formatter: function (cellvalue, options, rowObject) {
                var cellPrefix = '';
                return cellPrefix + '<a href= ${pageContext.request.contextPath}/registeredClassesDetail.phone?regNo='+ rowObject.regNo +'&courseId='+ rowObject.courseId +'">' + cellvalue + '</a>';
            }
        },],
        rowNum:5,
        height: 130,
        autowidth: true,
        pager: '#pager',
        hidegrid:false,
        viewrecord: true,
        emptyrecords: "Empty records",
        loadComplete: function() {},
        jsonReader : {
            root: "rows",
            page: "page",
            total: "total",
            records: "records",
            cell: "cell",
            repeatitems: false,
            id: "id"
        }
    });

    grid.jqGrid('navGrid','#pager',
        {add:false, edit:false, del:false, search:false}
    );
}); 
从控制器

,我想得到我发送的参数,即courseId和regNo。但是当我在控制器中调试时,两者都为空。我想使用这个2参数在域中搜索,以便它将显示正确的数据。请帮我。谢谢你的到来。

这是页面中显示详细信息的ajax代码。大致相同。但最重要的是我想要检索数据,以便我可以以任何形式显示。

    var jq = jQuery.noConflict();

 jq(document).ready(function() {
var grid = jq("#grid");
var regNo = '<%=request.getSession().getAttribute("regNo")%>';
var courseId = '<%=request.getSession().getAttribute("courseId")%>';

grid.jqGrid({
    url:'${pageContext.request.contextPath}/getRegisteredClassesDetails.html',
    datatype: 'json',
    mtype: 'POST',
    /* postData: {
        courseId: function() { return jQuery("#courseId option:selected").val(); },
        regNo: function() { return jQuery("#regNo option:selected").val(); }
    }, */
    postData:{regNo:regNo,
        courseId:courseId},  
   colNames:['Registration #', 'Status', 
    'Course Name', 'Location', 
    'Start Date', 'Registered Person'],

    colModel:[
        {name:'regNo',index:'regNo', width:20},
        {name:'regStatus',index:'regStatus', width:20},
        {name:'courseName',index:'courseName', width:150},
        {name:'courseLoc',index:'courseLoc', width:30},
        {name:'startDate',index:'startDate', width:25},
        {name:'fullName',index:'fullName', width:30,sortable:false}],
    rowNum:5,
    rowList:[5,10,20],
    height: 200,
    autowidth: true,
    pager: '#pager',
    sortname: 'startDate',
    hidegrid:false, //disable the collapse/expand function
    viewrecord: true,
    caption:"Course Details",
    emptyrecords: "Empty records",
    //multiselect:true,
    loadComplete: function() {

    },
    jsonReader : {
        root: "rows",
        page: "page",
        total: "total",
        records: "records",
        cell: "cell",
        repeatitems: false,
        id: "id"
    }
});

grid.jqGrid('navGrid','#pager',
    {add:false, edit:false, del:false, search:false}
);

});

1 个答案:

答案 0 :(得分:1)

`添加如下内容

postData: {
        courseId: function() { return jQuery('#courseId').val(); },
        regNo: function() { return jQuery('#regNo').val(); }
    },`