问题描述
在jqGrid中,添加行数据时是否可以定义单元格的标题(悬停)文本?
In jqGrid, is it possible to define a cell's Title (hover) text while adding row data?
var rowid;
for(var j=0;j<10;j++)
{
rowid = jQuery.Guid.New();
jQuery("#myJqGrid").jqGrid('addRowData',rowid,{Amount:"$"+j+".00",Date:"09/30/2015"});
}
我不想在网格完成后不必在网格上循环,因为在添加行时,更容易获得RowID和自定义悬停文本所需的数据.
I'd prefer not to not to have to loop over the grid after it has completed, as the RowID and the data that is needed for the custom hover text are more readily available while the row is being added.
谢谢!
推荐答案
如果只需要在网格中某些特定单元格上设置自定义工具提示,则可以使用 setCell (请参阅是一个示例).如果要在某个列的所有单元格上设置工具提示,但要使用自定义规则(不仅像单元格值一样使用相同的工具提示),最好使用 cellattr .例如,您可以使用
If you just need to set custom tooltip on some specific cells in the grid you can use setCell (see here an example). If you want to set tooltips on all cells of some column, but with a custom rule (not just the same tooltip like the cell value), you can better use cellattr. For example you can use
{name: 'name', index: 'name', width: 70,
cellattr: function (rowId, val, rawObject, cm, rdata) {
return 'title="' + rawObject.name + ' (' + rawObject.note + ')"';
}}
在此处中查看演示,该演示显示以下工具提示:
See the demo here which display the following tooltips:
如果您对性能感兴趣,则不应使用旧的addRowData
方法,该方法有很多缺点:
If you have an interest for performance you should not use old addRowData
method which has many disadvantages:
- 如果输入数据中有日期并使用格式符:"date",则必须使用
formatoptions: {reformatAfterEdit: true}
来正确格式化日期.在文档. - 您在该行之后插入的数据将全部放在同一页上.为了使本地日期分页正确,您必须再次重新加载网格.
- 将
data
参数与gridview: true
参数(上面的演示)结合使用,相对于addRowData
而言,网格包含的构建要慢得多.如果行数很大,您会看到差异. - 在创建使用
cellattr
和addRowData
的演示期间,我在该行,其中交换了两个参数rowid
和data
.我现在刚刚发布了错误报告.因此,要将cellattr
与addRowData
一起使用,必须在jquery.jqGrid.src.js
中进行小的修改.
- If you has date in input data and use formatter: 'date' then you have to use
formatoptions: {reformatAfter true}
to make the date correct formatted. You will find almost no information about the option in the documentation. - The data which you inserted row after the row will be all placed on the same page. To have correct local date paging you have to reload the grid one more time.
- Compare with the usage of
data
parameter in combination withgridview: true
parameter (the de demo above) the building of grid contain with respect ofaddRowData
is much slowly. You can see the difference if the number of row is large. - During creating of the demo which use
cellattr
andaddRowData
I found a bug in the jqGrid in the line where two parametersrowid
anddata
are swapped. I just now posted the bug report. So to usecellattr
together withaddRowData
you have to make small modification injquery.jqGrid.src.js
.
请参见使用addRowData
此处的演示.如果使用jquery.jqGrid.src.js
的修改版本(有关详细信息,请参见我的错误报告)
See the demo which use addRowData
here. If used modified version of jquery.jqGrid.src.js
(see my bug report for details)
这篇关于可以使用AddRowData定义jqGrid悬停文本吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!