jqGrid 将 SubGrid 宽度设置为行宽度

发布于 2024-11-07 19:41:58 字数 1020 浏览 3 评论 0原文

我正在使用一个简单的子网格创建 jqGrid。 我设置了属性

autowidth:true

以便 jqGrid 扩展到父元素的宽度。当我 扩展子网格未扩展至 jqGrid 宽度的行。子网格的宽度仍然是所有子网格列的总和。这是预期行为还是错误?

我需要使用 jQuery 手动设置子网格的宽度还是有其他方法?

这是我使用的代码示例:

jQuery("#list").jqGrid({ 
    url:'some-url.php', 
    mtype: "POST",
    datatype: "json",
    colNames:['Inv No','Date','Total'], 
    colModel:[  
                {name:'id',index:'id', width:55}, 
                {name:'amount',index:'amount', width:55}, 
                {name:'tax',index:'tax', width:55} 
    ], 
    multiselect: false,
    autowidth: true,
    rowNum:10, 
    rowList:[10,20,30], 
    pager: '#pager', 
    sortname: 'id', 
    sortorder: "desc",
    viewrecords: true, 
    subGrid : true, 
    subGridUrl: 'some-other-url.php', 
    subGridModel: [ {name:['CustomerId','CustomerName'], width:[55,55,]} ], 
    caption: "Subgrid Example",
    sortable: true        
}); 

jQuery("#list").jqGrid('navGrid','#pager',{add:false,edit:false,del:false});

I'm creating the jqGrid with a simple Subgrid.
I have set the property

autowidth:true

so that the jqGrid expands to the width of the parent element. When I
expand the row the Subgrid doesn't expand to the width of the jqGrid. The width of the Subgrid remains the sum of all Subgrid columns. Is this an expected behavior or a bug?

Do I need to use jQuery to manually set the width of the Subgrid or is there an another way?

This is an example of the code that I use:

jQuery("#list").jqGrid({ 
    url:'some-url.php', 
    mtype: "POST",
    datatype: "json",
    colNames:['Inv No','Date','Total'], 
    colModel:[  
                {name:'id',index:'id', width:55}, 
                {name:'amount',index:'amount', width:55}, 
                {name:'tax',index:'tax', width:55} 
    ], 
    multiselect: false,
    autowidth: true,
    rowNum:10, 
    rowList:[10,20,30], 
    pager: '#pager', 
    sortname: 'id', 
    sortorder: "desc",
    viewrecords: true, 
    subGrid : true, 
    subGridUrl: 'some-other-url.php', 
    subGridModel: [ {name:['CustomerId','CustomerName'], width:[55,55,]} ], 
    caption: "Subgrid Example",
    sortable: true        
}); 

jQuery("#list").jqGrid('navGrid','#pager',{add:false,edit:false,del:false});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦初醒的夏天 2024-11-14 19:41:59

我找到了替代解决方案,但它需要创建 jqGrid 作为子网格。然后子网格的宽度可以根据我们的需要进行调整。

这是代码示例,我希望有人会发现它有用:

   $("#list").jqGrid({ 
    url:'some-url.php', 
    mtype: "POST",
    datatype: "json",
    colNames:['Inv No','Date','Total'], 
    colModel:[  
                {name:'id',index:'id', width:55}, 
                {name:'amount',index:'amount', width:55}, 
                {name:'tax',index:'tax', width:55} 
    ], 
    multiselect: false,
    autowidth: true,
    rowNum:10, 
    rowList:[10,20,30], 
    pager: '#pager', 
    sortname: 'id', 
    sortorder: "desc",
    viewrecords: true, 
    subGrid : true, 
    subGridRowExpanded: function(subgrid_id, row_id) { 
    var subgrid_table_id, subgrid_pager_id, desired_width; 
            subgrid_table_id = subgrid_id+"_t";
            subgrid_pager_id = "p_"+subgrid_table_id; 
            desired_width = $("#list").width();
            desired_width -= 25;  // adjust this value as needed
            $("#"+subgrid_id).html("<table id='"+subgrid_table_id+
            "' class='scroll'></table><div id='"+subgrid_pager_id+"' class='scroll'></div>"); 
                jQuery("#"+subgrid_table_id).jqGrid({ 
                url:"subgrid-url.php?id="+row_id, 
                datatype: "json", 
                colNames: ['No','Item','Qty','Unit','Line Total'],  
                colModel: [ {name:"num",index:"num",width:80,key:true},  
                            {name:"item",index:"item",width:130},  
                            {name:"qty",index:"qty",width:70,align:"right"},  
                            {name:"unit",index:"unit",width:70,align:"right"},          
                            {name:"total",index:"total",width:70,align:"right",sortable:false} 
                ],  
                rowNum:20,  
                pager: pager_id,  
                sortname: 'num',  
                sortorder: "asc",  
                height: '100%',
                autowidth: false,
                width: desired_width
            });
        },
    caption: "Subgrid Example",
    sortable: true        
});

I have found alternative solution, but it requires creating jqGrid as subgrid. Then the width of the sub grid can be adjusted as we want.

This is as example of the code, I hope that somebody will find it useful:

   $("#list").jqGrid({ 
    url:'some-url.php', 
    mtype: "POST",
    datatype: "json",
    colNames:['Inv No','Date','Total'], 
    colModel:[  
                {name:'id',index:'id', width:55}, 
                {name:'amount',index:'amount', width:55}, 
                {name:'tax',index:'tax', width:55} 
    ], 
    multiselect: false,
    autowidth: true,
    rowNum:10, 
    rowList:[10,20,30], 
    pager: '#pager', 
    sortname: 'id', 
    sortorder: "desc",
    viewrecords: true, 
    subGrid : true, 
    subGridRowExpanded: function(subgrid_id, row_id) { 
    var subgrid_table_id, subgrid_pager_id, desired_width; 
            subgrid_table_id = subgrid_id+"_t";
            subgrid_pager_id = "p_"+subgrid_table_id; 
            desired_width = $("#list").width();
            desired_width -= 25;  // adjust this value as needed
            $("#"+subgrid_id).html("<table id='"+subgrid_table_id+
            "' class='scroll'></table><div id='"+subgrid_pager_id+"' class='scroll'></div>"); 
                jQuery("#"+subgrid_table_id).jqGrid({ 
                url:"subgrid-url.php?id="+row_id, 
                datatype: "json", 
                colNames: ['No','Item','Qty','Unit','Line Total'],  
                colModel: [ {name:"num",index:"num",width:80,key:true},  
                            {name:"item",index:"item",width:130},  
                            {name:"qty",index:"qty",width:70,align:"right"},  
                            {name:"unit",index:"unit",width:70,align:"right"},          
                            {name:"total",index:"total",width:70,align:"right",sortable:false} 
                ],  
                rowNum:20,  
                pager: pager_id,  
                sortname: 'num',  
                sortorder: "asc",  
                height: '100%',
                autowidth: false,
                width: desired_width
            });
        },
    caption: "Subgrid Example",
    sortable: true        
});
孤独患者 2024-11-14 19:41:59

你可以使用CSS:

td.subgrid-data div.tablediv table {
  width: 100%
}

You could use CSS:

td.subgrid-data div.tablediv table {
  width: 100%
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文