JQuery jqGrid loadComplete
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27278379/
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
JQuery jqGrid loadComplete
提问by Freigheist
I have a table built using jqGrid. If one cell is empty (gridtable1_Age), I want the text in another cell (gridtable1_Name) to be bold. I'm trying to use the loadComplete but it does not seem to be working or if I am using it in the right place.
我有一个使用 jqGrid 构建的表。如果一个单元格为空 (gridtable1_Age),我希望另一个单元格 (gridtable1_Name) 中的文本为粗体。我正在尝试使用 loadComplete 但它似乎不起作用或者我是否在正确的地方使用它。
jQuery("#grid1").jqGrid('setGridParam', opts).trigger("reloadGrid", [ {
page : 1,
loadComplete : function () {
$('td[aria-describedby=grid1_Age]:empty',
'#gridtable1').parent().find('td[aria-
describedby=grid1_Name]').css('font-weight', 'bold');
}
} ]);
Edit: My grid is built with Struts2 tags
编辑:我的网格是用 Struts2 标签构建的
回答by Oleg
I suppose you have Age
and Name
columns. What you can do is to define cellattr
property in Name
column which looks like below
我想你有Age
和Name
列。您可以做的是cellattr
在Name
如下所示的列中定义属性
cellattr: function (rowId, val, item) {
if (item.Age === "") { // or some very close test
return ' style="font-weight: bold;"';
}
}
In the case the grid will be createdwith correct CSS styles. It's more quickly as making any changed on the page (see the answerwhich describes that all modifications follow to additional reflow of the whole page and one should reduce modifications if it's possible).
在这种情况下,网格将使用正确的 CSS 样式创建。在页面上进行任何更改会更快(请参阅答案,其中描述了所有修改都遵循整个页面的额外回流,如果可能,应该减少修改)。
By the way the code which you posted don't work because the "empty" cell contains probably  
symbol.
顺便说一句,您发布的代码不起作用,因为“空”单元格可能包含 
符号。
回答by Verhaeren
I think grid1_Age
and grid1_name
need to be wraped with quotes in the selector like this:
我认为grid1_Age
并且grid1_name
需要在选择器中用引号括起来,如下所示:
loadComplete : function () {
$('td[aria-describedby="grid1_Age"]:empty', '#gridtable1').parent().find('td[aria-
describedby="grid1_Name"]').css('font-weight', 'bold');
}
If grid1_Age
and/or grid1_name
are variables and not literals then the right approach is:
如果grid1_Age
和/或是grid1_name
变量而不是文字,那么正确的方法是:
loadComplete : function () {
$('td[aria-describedby="'+grid1_Age+'"]:empty', '#gridtable1').parent()
.find('td[aria-describedby="'+grid1_Name+'"]').css('font-weight', 'bold');
}
} ]);