jqGrid的rowobject值是不确定的 [英] jqgrid rowobject value is undefined

查看:153
本文介绍了jqGrid的rowobject值是不确定的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code为绑定的值的jqGrid。

和我创建访问一个环节按钮特定的操作方法。

我需要的firstcolumn值传递给操作方法。

但是,如果我用这个继 HREF =@ Url.Action(ViewApplicants,HR)?JobsID =+ rowObject [0] +'。它显示未定义值。如何解决这个问题?

 < D​​IV>
        <表ID =Jobtable>< /表>
        < D​​IV ID =jQGridPager>< / DIV>
        < D​​IV ID =对话框中的标题=查看作业详细信息>< / DIV>
    < / DIV>    <脚本类型=文/ JavaScript的>
            $(文件)。就绪(函数(){
                $(#Jobtable)。jqGrid的({
                    网址:'/ HR / PassJsonJob /',
                    数据类型:JSON
                    MTYPE:'GET',
                    colNames:作业ID,职务,工作经验,工作地点,ViewApplicants'],
                    colModel:
                                {名称:'JobsID',索引:JobsID',宽度:150,排列:'左',可编辑:真正},
                                {名称:'JOBTITLE',索引:JOBTITLE',宽度:150,排列:'左',可编辑:真正},
                                {名称:'JobExperience',索引:JobExperience',宽度:150,排列:'左',可编辑:真正},
                                {名称:'JobLocation',索引:JobLocation',宽度:150,排列:'左',可编辑:真正},
                                {
                                    名称:'ViewApplicants',索引:ViewApplicants',宽度:150,排序:假的,
                                    格式化:功能(cellvalue,期权,rowObject){
                                        警报(rowObject)
                                        返回&下; A HREF =@ Url.Action(ViewApplicants,HR)JobsID =?+ rowObject [0] +'>查看申请人下; / A>中;
                                     }
                                }
                    ]
                    的rowNum:10,
                    rowList:[10,20,30],
                    viewrecords:真实,
                    loadonce:真实,
                    GridView控件:真实,
                    呼叫器:#jQGridPager
                    cellEdit:假的,
                    rowNumbers:真实,
                    宽度:1000,
                    标题:应用乔布斯,
                    viewrecords:真
                })
                $('#Jobtable')。的jqGrid('navGrid','#jQGridPager',
                {
                    编辑:真的,
                    补充:假的,
                    德尔:假的,
                    观点:假的,
                    搜索:假的
                });
            });
        < / SCRIPT>


解决方案

要知道从网址服务器响应的格式,这一点很重要/ HR / PassJsonJob / rowObject 的格式对应于从服务器响应项目的格式。因此,它可能是 rowObject.JobsID 而不是 rowObject [0] 将正确的方法来访问 JobsID 属性。因为你用 loadonce:真正的 rowObject 的格式可以是 rowObject [0] 是在第一负载。后来,例如,在数据的本地分页或排序, rowObject 的格式将与 JobsID 对象属性,所以 rowObject.JobsID 将是正确的。

所以 rowObject.JobsID rowObject的使用[0] || rowObject.JobsID 可以解决您的问题。

还有一个选择是使用属性键:真正的 JobsID 列的定义 colModel 。一个可以使用的只有 JobsID 包含的唯一每一行中值的属性。在这种情况下的jqGrid将使用 JobsID 列的值ROWID: ID 属性分配给该行的值( < TR>在格元素)。在这种情况下人们可以使用 options.rowId 访问 JobsID 值。

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>

解决方案

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.

这篇关于jqGrid的rowobject值是不确定的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆