sone
sone

Reputation: 161

pass parameter from jqgrid to spring controller?

i have this ajax code. i tried also the onselectrow,formatter, how i want to get the row object and send it to the controller so that my next page can display all the details of the row object send.

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}
    );
}); 

from the controller, i want to get the parameter i have send which is courseId and regNo. but when i debug in the controller, both are null. i want to use this 2 parameter to search in the domain so that it will display the correct data. Please help me. Thanks is advance.

and this is the ajax code in the page that will display the details.It mostly the same. but the most important i want to retrieve the data so that i can display in any form.

    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}
);

});

Upvotes: 0

Views: 1472

Answers (1)

Jitendra Sahoo
Jitendra Sahoo

Reputation: 11

`Add something like below

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

Upvotes: 1

Related Questions