【问题标题】:How to apply a css class for jqGrid height property setGridHeight?如何为 jqGrid 高度属性 setGridHeight 应用 css 类?
【发布时间】:2025-12-09 13:10:02
【问题描述】:

我们的目标是申请media query css class

截至目前,下面的代码使用$(window).height() 来查找height

$('#list').jqGrid('setGridHeight', $(window).height() - 380);

我需要应用css class,而不是使用$(window).height() - 380。谢谢。

【问题讨论】:

  • 使用 CSS 你无法计算 $(window).height()
  • 我需要提到Media Query css class name 而不是$(window).height() - 380。那么,如何在此处添加css class。谢谢。
  • 你不能在那里分配类名。只有您可以分配变量。或者你可以为#list添加类
  • 我试过$('#list').addClass('grid_height');,其中grid_heightheight:50px;但是,这些变化不会反映在网格中。

标签: jquery html css jqgrid


【解决方案1】:

您可以尝试使用以下

// place hidden test div
var $testDiv = $("<div style='display:none'></div>");
$testDiv.addClass("grid_height").appendTo("body");
// I hope you will grid_height from correct media

// alternatively you can try to use
//     $("#list").addClass("grid_height");
// but BEFORE you create jqGrid

var height = parseInt($testDiv.css("height"), 10);
$testDiv.remove();

// now you can use height variable to set grid height
$("#list").jqGrid("setGridHeight", height);

更新The demo 似乎有效。

【讨论】:

  • 我得到的值为"0px" for $testDiv.css("height")。我的css 看起来如下.grid_height { height:50px; }。我需要得到50px 或我的css class name 中的任何内容。谢谢。
  • @JohnStephen: 看看the demo 和青春对比一下。
最近更新 更多