根据网格中的cloumn数量来调整jqGrid的大小 [英] Resize jqGrid according to number of cloumns in the grid

查看:365
本文介绍了根据网格中的cloumn数量来调整jqGrid的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有jqGrid(免费jqGrid),包含7列。我使用 shrinkToFit:false 属性来启用网格列的滚动(适合移动设备)。当我将相同的属性应用于只有一个列网格的网格时,如下图所示:

I have jqGrid (free jqGrid) that contains 7 columns. And I applied shrinkToFit: false, property to enable scrolling for the grid columns (to fit to mobile device). When I applied the same property to the grid having only one column grid is looking like below image :

请告诉我如何根据列数自动设置网格宽度。

Please tell me how to automatically set grid width according to the number of columns.

推荐答案

您可以使用 setColWidth 方法(包含在免费jqGrid )动态更改最后一列的宽度。我不知道加载您使用的网格的情况。 演示的修改可能如下: http://jsfiddle.net/OlegKi/andm1299/37/ 其中

You can use setColWidth method (included in free jqGrid) to change the width of the last column dynamically. I don't know which scenario for loading the grid you use. The modification of the demo could be the following: http://jsfiddle.net/OlegKi/andm1299/37/ where

$(window).bind("resize", function () {
    var p = $grid.jqGrid("getGridParam"),
        cm = p.colModel[p.iColByName.ComboDuration];

    $grid.jqGrid("setGridWidth", $grid.closest(".container-fluid").width());
    $grid.jqGrid("setColWidth", "ComboDuration", p.width - p.tblwidth + cm.width);
}).triggerHandler("resize");

上述代码首先根据外层容器的宽度调整网格宽度,然后调整基于主网格表的宽度和网格的总宽度之间的差的最后一列的宽度。

The above code first resize the width of grid based on the width of the outer container and then adjust the width of the last column based on the difference between the width of the main grid table and the total width of the grid.

这篇关于根据网格中的cloumn数量来调整jqGrid的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆