Javascript 可以让 jqGrid 拉伸到 100% 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3055321/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:07:58  来源:igfitidea点击:

Possible to make jqGrid stretch to 100%?

javascriptjquerycssjqgrid

提问by Earlz

Is it possible to make it so that a jqGrid will have a width set to 100%? I understand that column widths must be an absolute pixel size, but I've yet to find anything for setting the width of the actual grid to a relative size. For instance, I want to set the width to 100%. Instead of 100% it seems to use an odd size of 450px. There is more horizontal room on the page, but with the columns width and such, it will make the container(of only the grid) horizontally scroll. Is there some way around this?

是否可以将 jqGrid 的宽度设置为 100%?我知道列宽必须是绝对像素大小,但我还没有找到任何将实际网格的宽度设置为相对大小的方法。例如,我想将宽度设置为 100%。而不是 100% 它似乎使用 450px 的奇怪大小。页面上有更多的水平空间,但随着列宽等,它会使容器(只有网格)水平滚动。有没有办法解决这个问题?

采纳答案by Earlz

I ended up using the jqGrids.fluid extensionto do this and it worked great.

我最终使用jqGrids.fluid 扩展来做到这一点,而且效果很好。

UPDATE: That link seems to be dead, but the archived article can be viewed here.

更新:该链接似乎已失效,但可以在此处查看存档文章。

回答by johnjohn

autowidth: truefrom 3.5 onwards

autowidth: true从 3.5 开始

回答by user1697051

It works for me:

这个对我有用:

width: null,
shrinkToFit: false,

回答by Bhargav

I'm using this to set the width of the grid to the width of the parent container.

我正在使用它来将网格的宽度设置为父容器的宽度。

function resizeGrid() {
        var $grid = $("#list"),
        newWidth = $grid.closest(".ui-jqgrid").parent().width();
        $grid.jqGrid("setGridWidth", newWidth, true);
}

回答by Oleg

You can try to fix the width of jqGrid with respect of a function which I described here Correctly calling setGridWidth on a jqGrid inside a jQueryUI Dialog

您可以尝试根据我在此处描述的函数来修复 jqGrid 的宽度在 jQueryUI 对话框中正确调用 jqGrid 上的 setGridWidth

回答by molson

wonderful function for this i found here (stackoverflow) cannot remember the post. I have the height portion commented out keep that in mind (was not working for me) but the width is perfect. throw this anywhere in your php file.

我在这里找到的很棒的功能(stackoverflow)不记得这篇文章了。我已经注释掉了高度部分,请记住这一点(对我不起作用)但宽度是完美的。把它扔到你的 php 文件中的任何地方。

$resize = <<<RESIZE
jQuery(window).resize(function(){
    gridId = "grid";

    gridParentWidth = $('#gbox_' + gridId).parent().width();
    $('#' + gridId).jqGrid('setGridWidth',gridParentWidth);

   // $('#' + gridId).jqGrid('setGridHeight', //Math.min(500,parseInt(jQuery(".ui-jqgrid-btable").css('height'))));
})
RESIZE;

回答by Yuriy

Try to set width to "null". It works for me.

尝试将宽度设置为“空”。这个对我有用。

$(grid).jqGrid({
   width: null,
});

回答by Surbhit

loadComplete : function () {
     $("#gridId").jqGrid('setGridWidth', $(window).width(), true); 
},

回答by Justin Ethier

It looks like this is not supported. According to the docs for setGridWidth:

好像不支持这个。根据setGridWidth的文档:

Sets a new width to the grid dynamically. The parameters are: new_width is the new width in pixels...

动态设置网格的新宽度。参数是: new_width 是以像素为单位的新宽度...

The docs for the widthoption also do not mention being able to set width as a percentage.

width选项的文档也没有提到能够将宽度设置为百分比。

That being said, you can use the autowidthfeature or a similar technique to give the grid the correct initial width. Then follow the methods discussed in resize-jqgrid-when-browser-is-resizedto ensure the grid is properly resized when the browser window is resized, which will simulate the effect of having 100% width.

话虽如此,您可以使用该autowidth功能或类似技术为网格提供正确的初始宽度。然后按照resize-jqgrid-when-browser-is-resized 中讨论的方法来确保在调整浏览器窗口大小时正确调整网格大小,这将模拟具有 100% 宽度的效果。

回答by Richard

Simpler

更简单

  $("#gridId").setGridWidth($(window).width() );