admin管理员组

文章数量:1405170

I use the following code for bind the values in jqgrid.

And i create one link button for access the Particular Action Method.

I need to pass the firstcolumn value to the action method.

But ,If i use this Following href='@Url.Action("ViewApplicants", "HR")?JobsID="+rowObject[0]+" '.It show the undefined Value .How to solve this?

 <div>
        <table id="Jobtable"></table>
        <div id="jQGridPager"></div>
        <div id="dialog" title="View Job Detail"></div>
    </div>

    <script type="text/javascript">
            $(document).ready(function () {
                $("#Jobtable").jqGrid({
                    url: '/HR/PassJsonJob/',
                    datatype: "json",
                    mtype: 'GET',
                    colNames: ['Job ID', 'Job Title', 'Job Experience', 'Job Location', 'ViewApplicants'],
                    colModel: [
                                { name: 'JobsID', index: 'JobsID', width: 150, align: 'left', editable: true },
                                { name: 'JobTitle', index: 'JobTitle', width: 150, align: 'left', editable: true },
                                { name: 'JobExperience', index: 'JobExperience', width: 150, align: 'left', editable: true },
                                { name: 'JobLocation', index: 'JobLocation', width: 150, align: 'left', editable: true },
                                {
                                    name: 'ViewApplicants', index: 'ViewApplicants', width: 150, sortable: false,
                                    formatter: function (cellvalue, options, rowObject) {
                                        alert(rowObject)
                                        return "<a href='@Url.Action("ViewApplicants", "HR")?JobsID="+rowObject[0]+"'>View Applicants</a>";
                                     }
                                }
                    ],
                    rowNum: 10,
                    rowList: [10, 20, 30],
                    viewrecords: true,
                    loadonce: true,
                    gridview: true,
                    pager: "#jQGridPager",
                    cellEdit: false,
                    rowNumbers: true,
                    width: 1000,
                    caption: 'Applied Jobs',
                    viewrecords: true
                })
                $('#Jobtable').jqGrid('navGrid', '#jQGridPager',
                {
                    edit: true,
                    add: false,
                    del: false,
                    view: false,
                    search: false
                });
            });


        </script>

I use the following code for bind the values in jqgrid.

And i create one link button for access the Particular Action Method.

I need to pass the firstcolumn value to the action method.

But ,If i use this Following href='@Url.Action("ViewApplicants", "HR")?JobsID="+rowObject[0]+" '.It show the undefined Value .How to solve this?

 <div>
        <table id="Jobtable"></table>
        <div id="jQGridPager"></div>
        <div id="dialog" title="View Job Detail"></div>
    </div>

    <script type="text/javascript">
            $(document).ready(function () {
                $("#Jobtable").jqGrid({
                    url: '/HR/PassJsonJob/',
                    datatype: "json",
                    mtype: 'GET',
                    colNames: ['Job ID', 'Job Title', 'Job Experience', 'Job Location', 'ViewApplicants'],
                    colModel: [
                                { name: 'JobsID', index: 'JobsID', width: 150, align: 'left', editable: true },
                                { name: 'JobTitle', index: 'JobTitle', width: 150, align: 'left', editable: true },
                                { name: 'JobExperience', index: 'JobExperience', width: 150, align: 'left', editable: true },
                                { name: 'JobLocation', index: 'JobLocation', width: 150, align: 'left', editable: true },
                                {
                                    name: 'ViewApplicants', index: 'ViewApplicants', width: 150, sortable: false,
                                    formatter: function (cellvalue, options, rowObject) {
                                        alert(rowObject)
                                        return "<a href='@Url.Action("ViewApplicants", "HR")?JobsID="+rowObject[0]+"'>View Applicants</a>";
                                     }
                                }
                    ],
                    rowNum: 10,
                    rowList: [10, 20, 30],
                    viewrecords: true,
                    loadonce: true,
                    gridview: true,
                    pager: "#jQGridPager",
                    cellEdit: false,
                    rowNumbers: true,
                    width: 1000,
                    caption: 'Applied Jobs',
                    viewrecords: true
                })
                $('#Jobtable').jqGrid('navGrid', '#jQGridPager',
                {
                    edit: true,
                    add: false,
                    del: false,
                    view: false,
                    search: false
                });
            });


        </script>
Share Improve this question asked Jun 24, 2014 at 11:03 V.VV.V 8833 gold badges25 silver badges56 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

It's important to know the format of the server response from the URL /HR/PassJsonJob/. The format of rowObject corresponds to the format of items from the server response. So it could be that rowObject.JobsID instead of rowObject[0] would correct way to access JobsID property. Because you use loadonce: true the format of rowObject could be rowObject[0] at the first load. Later, for example, at local paging or sorting of data, the format of rowObject will be object with JobsID property, so rowObject.JobsID will be correct.

So the usage of rowObject.JobsID or rowObject[0] || rowObject.JobsID could fix your problem.

One more option could be to use the property key: true in the definition of JobsID column in colModel. One can use the property only if JobsID contains unique values in every row. In the case jqGrid will use the value from JobsID column as rowid: the value of id attribute assigned to the rows (<tr> elements) of the grid. In the case one could use options.rowId to access the JobsID value.

UPDATED: One more option exists in free jqGrid fork, which I develop since the end of 2014. The 2-d parameter (options) of the custom formatter has the property rowData, which contains the same information like rowObject, but it has always object format. Thus it's safe to use options.rowData.JobsID instead of rowObject[0] || rowObject.JobsID. One don't need to use the 3-d parameter of the the custom formatter at all. Free jqGrid didn't changed the format of the 3-d parameter to have the best upwards patibility to the previous versions of jqGrid.

本文标签: javascriptjqgrid rowobject value is undefinedStack Overflow