简体   繁体   English

如何在JQgrid中获取特定的单元格值

[英]How to get the particular cell value in JQgrid

I have written a JQGrid which was working fine but I need to fill the sub grid based on the selected row of main grid. 我编写了一个工作正常的JQGrid,但是我需要根据所选的主网格行填充子网格。 How can I get the selected row cell value to pass in the url of subgrid. 如何获取选定的行单元格值以传递子网格的url。

columns in the main grid ---- Id,Firstname,Lastname,Gender. 主网格中的列---- Id,Firstname,Lastname,Gender。

I need to get selected row of "Id" value. 我需要获取“ Id”值的选定行。

Here is my script 这是我的剧本

$(document).ready(function () {


            jQuery("#EmpTable").jqGrid({

                datatype: 'json',
                url: "Default1.aspx?x=getGridData",
                mtype: 'POST',
                ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
                serializeGridData: function (postData) {
                    return JSON.stringify(postData);
                },
                jsonReader: { repeatitems: false, root: "rows", page: "page", total: "total", records: "records" },


                colNames: ['PID', 'First Name', 'Last Name', 'Gender'],
                colModel: [
                    { name: 'PID', width: 60, align: "center", hidden: true, searchtype: "integer", editable: true },
                    { name: 'FirstName', width: 180, sortable: true, hidden: false, editable: true, sorttype: 'string', searchoptions: { sopt: ['eq', 'bw']} },
                    { name: 'LastName', width: 180, sortable: false, hidden: false, editable: true },
                    { name: 'Gender', width: 180, sortable: false, hidden: false, editable: true, cellEdit: true, edittype: "select", formater: 'select', editrules: { required: true, edithidden: true }, editoptions: { value: getAllSelectOptions()}}],
                loadonce: true,
                pager: jQuery('#EmpPager'),
                rowNum: 5,
                rowList: [5, 10, 20, 50],
                viewrecords: true,
                sortname: 'PID',
                sortorder: "asc",
                height: "100%",
                editurl: 'Default1.aspx?x=EditRow',
                subGrid: true,
                // subGridUrl: 'Default1.aspx?x=bindsubgrid',
                subGridRowExpanded: function (subgrid_id, row_id) {

                   // var celValue = jQuery('#EmpTable').jqGrid('getCell', rowId, 'PID');

                    var subgrid_table_id, pager_id;
                    subgrid_table_id = subgrid_id + "_t";
                    pager_id = "p_" + subgrid_table_id;
                    $("#" + subgrid_id).html("");
                    jQuery("#" + subgrid_table_id).jqGrid({
                        url: "Default1.aspx?x=bindsubgrid&PID=" + row_id + "",
                        datatype: "json",
                        mtype: 'POST',
                        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
                        serializeGridData: function (postData) {
                            return JSON.stringify(postData);
                        },
                        jsonReader: { repeatitems: false, root: "rows", page: "page", total: "total", records: "records" },

                        colNames: ['PID', 'First Name', 'Last Name', 'Gender'],
                        colModel: [
                    { name: 'PID', width: 60, align: "center", hidden: true, searchtype: "integer", editable: true },
                    { name: 'FirstName', width: 180, sortable: true, hidden: false, editable: true, sorttype: 'string', searchoptions: { sopt: ['eq', 'bw']} },
                    { name: 'LastName', width: 180, sortable: false, hidden: false, editable: true },
                    { name: 'Gender', width: 180, sortable: false, hidden: false, editable: true, cellEdit: true, edittype: "select", formater: 'select', editrules: { required: true, edithidden: true }, editoptions: { value: getAllSelectOptions()}}],
                        loadonce: true,
                        rowNum: 5,
                        rowList: [5, 10, 20, 50],
                        pager: pager_id,
                        sortname: 'PID',
                        sortorder: "asc",
                        height: '100%'
                    });
                    jQuery("#" + subgrid_table_id).jqGrid('navGrid', "#" + pager_id, { edit: false, add: false, del: false })
                }

            })

Please help to find the cell value. 请帮助查找单元格值。

Thanks purna 谢谢普纳

If 'PID' column contains unique value which can be used as the rowid then you should add key: true in the definition of the 'PID' column in colModel . 如果'PID'列包含可用作行标识符的唯一值,则应在colModel'PID'列的定义中添加key: true jqGrid will assign id attribute of <tr> elements (the rows of the grid) to the value from 'PID' column. jqGrid会将<tr>元素的id属性(网格的行)分配给'PID'列中的值。 After that row_id parameter of subGridRowExpanded will contain the value which you need and you will don't need to make any additional getCell call. 此后row_id的参数subGridRowExpanded将包含你所需要的价值,你将不需要做任何额外的getCell电话。

Additional remark: I strictly recommend you to use idPrefix parameter for subgrids and probably for the grids. 补充说明:我严格建议您idPrefix网格甚至可能对网格使用idPrefix参数。 In the case jqGrid will use the value of id attribute which have the specified prefix. 在这种情况下,jqGrid将使用具有指定前缀的id属性的值。 If will allow to solve conflicts (id duplicates in HTML page). 如果允许解决冲突(HTML页面中的ID重复)。 Currently you can have the same rowids for the rows of subgrids and to the rows of the main grid. 当前,子网格的行和主网格的行可以具有相同的rowid。 See here more my old answers on the subject. 在这里看到我关于这个问题的旧答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM