1


上次我在我的应用程序中更改了 jqGrid(4.6.0 到 free-jqgrid 4.8.0)和 jQuery(1.7.2 到 2.1.3)的版本。
在我的父网格中,我有 2 个可见列,每个列的宽度为 100 像素,在子网格中,有 5 个可见列,每个列的宽度为 200 像素。在以前的版本中,子网格位于顶部,因此我可以查看子网格中的所有列,而无需调整任何列的大小。
更改后获得相同的结果如果我想查看子网格中的所有列,我需要做解决方法并添加空列(我不想这样做)。有什么我可以做的吗?
它可以与父网格中更大的第二列一起使用,但我不想调整它的大小,我更喜欢将其保留为 100 像素。

网格的定义:

function loadFirstGrid() {
        var data = {
            "page": "1",
            "records": "3",
            "rows": [
            { "DataID": "1", "DataDesc": "Test 1", "DataTitle": "Test 1" },
            { "DataID": "2", "DataDesc": "Test 2", "DataTitle": "Test 2" },
            { "DataID": "3", "DataDesc": "Test 3", "DataTitle": "Test 3" }
        ]
        };

        $("#FirstGrid").jqGrid({
            datatype: "xml",
            mtype: "GET",
            contentType: "text/xml",
            colNames: ['DataID', 'DataDesc', 'DataTitle'],
            colModel: [
            { name: 'DataID', index: 'DataID', hidden: true, key: true },
            { name: 'DataDesc', index: 'DataDesc', width: 100 },
            { name: 'DataTitle', index: 'DataTitle', width: 100 }
          ],
            rowNum: 10000,
            datatype: "jsonstring",
            datastr: data,
            ignoreCase: true,
            sortname: 'DataDesc',
            sortorder: 'asc',
            emtyrecords: "Nothing to display",
            viewrecords: true,
            sortable: true,
            height: "100%",
            shrinkToFit: false,
            loadonce: true,
            scrollOffset: 0,
            width: 2000,
            caption: 'First Grid',
            subGrid: true,
            subGridRowExpanded: loadSubGrid,
            gridview: false
        });
    }

    function loadSubGrid(subgrid_id, row_id) {
        var data = {
            "page": "1",
            "records": "3",
            "rows": [
            { "SubGridID": "1", "FirstCol": "Test 1", "SecondCol": "Test 1", "ThirdCol": "Test 1", "FourthCol": "Test 1", "FifthCol": "Test 1" },
            { "SubGridID": "2", "FirstCol": "Test 2", "SecondCol": "Test 2", "ThirdCol": "Test 1", "FourthCol": "Test 1", "FifthCol": "Test 1" },
            { "SubGridID": "3", "FirstCol": "Test 3", "SecondCol": "Test 3", "ThirdCol": "Test 1", "FourthCol": "Test 1", "FifthCol": "Test 1" }
        ]
        };

        var subgrid_table_id;
        var dataID = $("#FirstGrid").jqGrid('getRowData', row_id).DataID;
        subgrid_table_id = subgrid_id + "_SubGrid";
        $("#" + subgrid_id).html("<div><table id='" + subgrid_table_id + "' class='scroll'></table></div>");
        $("#" + subgrid_table_id).jqGrid({
            datatype: "xml",
            mtype: "GET",
            contentType: "text/xml",
            colNames: ['SubGridID', 'FirstCol', 'SecondCol', 'ThirdCol', 'FourthCol', 'FifthCol'],
            colModel: [
                { name: 'SubGridID', index: 'SubGridID', hidden: true, key: true },
                { name: 'FirstCol', index: 'FirstCol', editable: false, width: 200 },
                { name: 'SecondCol', index: 'SecondCol', width: 200 },
                { name: 'ThirdCol', index: 'ThirdCol', width: 200 },
                { name: 'FourthCol', index: 'FourthCol', width: 200 },
                { name: 'FifthCol', index: 'FifthCol', width: 200 },
              ],
            rowNum: 10000,
            datatype: "jsonstring",
            datastr: data,
            ignoreCase: true,
            sortname: 'FirstCol',
            sortorder: 'asc',
            emtyrecords: "Nothing to display",
            viewrecords: true,
            sortable: true,
            height: "100%",
            shrinkToFit: false,
            loadonce: true,
            scrollOffset: 0,
            width: 1900,
            caption: 'SubGrid',
            gridview: false
        });
    }

编辑:这里
有演示 谢谢!

4

1 回答 1

0

与 jqGrid 4.7 相比,free jqGrid 4.8 的 CSS 结构有很多变化。所以我建议以另一种方式解决您的问题。您可以在父网格的末尾添加新的最后一列。该列可以有空标题。结果,父网格看起来与之前完全一致,但现在您将没有所描述的问题。

我将您的演示修改为以下http://jsfiddle.net/OlegKi/2tkkqbeq/4/。我删除了许多不需要的设置,例如class='scroll'datatype: "xml"(不能与一起使用datatype: "jsonstring")。我. _index _ colModel我删除了一些其他现在默认的属性。

删除gridview: false使网格工作缓慢而没有其他优势的属性很重要。我建议您使用datatype: "local"withdata: data.rows而不是datatype: "jsonstring", datastr: data. 更改的主要优点:输入数据将按 jqGrid 排序,对应于sortname您使用的选项。

我建议您autowidth: true在子网格中使用。

我在您的演示中所做的最后一个但非常重要的更改是idPrefix: "s_" + row_id + "_"在子网格中包含该选项。如果不使用该选项,您将在页面上出现id 重复项,因为主网格和子网格将具有相同的id值(1、2、3)。

于 2015-04-08T11:20:27.950 回答