JqG​​rid-在页面加载时扩展子网格

时间:2010-08-15 11:29:50

标签: jqgrid subgrid

我的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>

提前致谢, Ancy

1 个答案:

答案 0 :(得分: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