根据网格中的列数调整jqGrid的大小 [英] Resize jqGrid according to number of columns in the grid

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

问题描述

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

如何根据列数自动设置网格宽度?

解决方案

您可以使用setColWidth方法(包含在演示的修改如下:

上面的代码首先根据外部容器的宽度调整网格的宽度,然后根据主网格表的宽度与网格总宽度之间的差来调整最后一列的宽度. /p>

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 :

How to automatically set grid width according to the number of columns?

解决方案

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.

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

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