【问题标题】:JqGrid- Expanding Subgrid on page loadJqG​​rid-在页面加载时扩展子网格
【发布时间】:2011-03-30 01:35:44
【问题描述】:

我的 MVC 2 项目中有一个启用了子网格的 Jqgrid。子网格在按钮单击时展开并填充数据。我想在页面加载时展开并显示子网格数据。所以我在父网格的 gridComplete 事件上调用了 exapandSubGridRow 方法。现在的问题是,子网格行在页面加载时展开,但没有数据,父网格行下方出现一个空行。这是我的代码,谁能帮我解决这个问题。

<script type="text/javascript">
   jQuery(document).ready(function () {
        jQuery("#list").jqGrid({
            url: '/jqgrid/DynamicGridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['SurveyQnGrpId', 'SurveyQnGroup1'],
            colModel: [
              { name:'SurveyQnGrpId', index:'SurveyQnGrpId', width:40, align:'left' },
              { name:'SurveyQnGroup1',index: 'SurveyQnGroup1',width: 400,
                align: 'left'}],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'SurveyQnGrpId',
            sortorder: "SurveyQnGroup1",
            viewrecords: true,
            caption: 'My first grid',
            subGrid: true,
            subGridUrl: '/jqgrid/InnerGridData/',
            subGridModel: [{
                name: ['SurveyQnGrpId','SurveyQnId', 'SurveyQn', 'SurveyQnCategory',
                       'MandatoryQn','RadioOption3'],
                width: [10,10, 100, 10, 10,10],
                align: ['left', 'left', 'left', 'left'],
                params: ['SurveyQnGrpId']
            }],
            gridComplete: function () {
                var rowIds = $("#list").getDataIDs();
                $.each(rowIds, function (index, rowId) {
                        $("#list").expandSubGridRow(rowId); 
                }); 
            } 
        });
    });
</script>

提前致谢, 安西

【问题讨论】:

    标签: jqgrid subgrid


    【解决方案1】:

    我不知道在问这个问题时这是否可用,但我发现有一个 subGridOptions 属性,需要一个对象。该对象中的属性之一是expandOnLoad,当设置为 true 时,将在加载网格时扩展父网格中的行:

    jQuery(document).ready(function () {
        jQuery("#list").jqGrid({
            url: '/jqgrid/DynamicGridData/',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['SurveyQnGrpId', 'SurveyQnGroup1'],
            colModel: [
              { name:'SurveyQnGrpId', index:'SurveyQnGrpId', width:40, align:'left' },
              { name:'SurveyQnGroup1',index: 'SurveyQnGroup1',width: 400,
                align: 'left'}],
            pager: jQuery('#pager'),
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'SurveyQnGrpId',
            sortorder: "SurveyQnGroup1",
            viewrecords: true,
            caption: 'My first grid',
            subGrid: true,
            subGridOptions: { expandOnLoad: true },
            subGridUrl: '/jqgrid/InnerGridData/',
            subGridModel: [{
                name: ['SurveyQnGrpId','SurveyQnId', 'SurveyQn', 'SurveyQnCategory',
                       'MandatoryQn','RadioOption3'],
                width: [10,10, 100, 10, 10,10],
                align: ['left', 'left', 'left', 'left'],
                params: ['SurveyQnGrpId']
            }],
            gridComplete: function () {
                var rowIds = $("#list").getDataIDs();
                $.each(rowIds, function (index, rowId) {
                        $("#list").expandSubGridRow(rowId); 
                }); 
            } 
        });
    });
    

    见:http://www.trirand.com/jqgridwiki/doku.php?id=wiki:subgrid

    【讨论】:

    • expandOnLoad 似乎是 subGridOptions 的属性,而不是 subGridModel
    • 糟糕!接得好。已编辑。
    猜你喜欢
    • 2011-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-25
    • 2012-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多