jqGrid-带有TD元素的单元格 [英] jqGrid - cells with TD elements inside
问题描述
我似乎在使用jQuery Grid(jqGrid)时遇到了一个问题,如果我加载了其中一个单元格内部有一个表的数据,则在触发onSelectRow()
并调用$(grid).getRowData(rowid)
时会引发错误.
I seem to have an issue where with jQuery Grid (jqGrid) if I have loaded data where one of the cells has a table inside, it throws an error when onSelectRow()
is fired and I call $(grid).getRowData(rowid)
.
jqGrid似乎正在枚举所选行中的所有TD元素(包括那些在给定单元格中表子元素的元素).
jqGrid seems to be enumerating ALL of the TD elements in the selected row (including those which are children of the table within a given cell).
是否有适当的方法来执行此操作或防止jqGrid枚举这些元素? :(
Is there a proper way to do this or to prevent jqGrid from enumerating those elements? :(
在我的特殊情况下,HTML一直隐藏到需要为止,因此我能够在服务器上用"xtd"替换TD,直到发送给客户端为止.在客户端,当我需要HTML时,只需将"xtd"替换为"td".仍然希望有更好的方法.
In my particular case, the HTML was hidden until needed, so I was able to replace the TD's with "xtd" on the server until sent out to the client. On the client-side, when I needed them HTML, I just replace "xtd" to "td". Still wish there was a better way.
我想澄清一下,我想要一种不修改插件的方法.精心编写的修改还是不错的.
I want to clarify, I desire a method of doing this that doesn't modify the plugin. An well-written modification would still be nice.
推荐答案
旧但尚未解决.
嗨. 是的,jqGrid的内部table
和td
存在问题,但是有一个快速而有用的修复程序.在文件jquery.jqGrid.min
(jqGrid 3.8.2-jQuery Grid)中.将文件放入 js-beutifier 或获取未缩小的版本,然后找到getRowData
函数.然后,您必须为每个b("td", r).each(function (t) {
的查找添加额外条件,以对 b("td[id!='-1']", r).each(function (t) {
进行编码.在内部表中,您应该声明<td id="-1">
.在这种情况下,您将td排除在colModel
中.
Hi. Yes jqGrid has problem with inner table
and td
but there is a quick and useful fix. In file jquery.jqGrid.min
(jqGrid 3.8.2 - jQuery Grid). Put file into js-beutifier or get not minified version and find getRowData
function. Then you have to add extra condition to lookup foreach b("td", r).each(function (t) {
to code b("td[id!='-1']", r).each(function (t) {
. In your inner table you should declare <td id="-1">
. In this case you exclude your td from searching in colModel
.
复制/粘贴此代码:
getRowData: function (f) {
var j = {},
i, c = false,
e, k = 0;
this.each(function () {
var n = this,
a, r;
if (typeof f == "undefined") {
c = true;
i = [];
e = n.rows.length
} else {
r = n.rows.namedItem(f);
if (!r) return j;
e = 2
}
for (; k < e;) {
if (c) r = n.rows[k];
if (b(r).hasClass("jqgrow")) {
b("td[id!='-1']", r).each(function (t) {//fix
a = n.p.colModel[t].name;
if (a !== "cb" && a !== "subgrid" && a !== "rn") if (n.p.treeGrid === true && a == n.p.ExpandColumn) j[a] = b.jgrid.htmlDecode(b("span:first", this).html());
else try {
j[a] = b.unformat(this, {
rowId: r.id,
colModel: n.p.colModel[t]
}, t)
} catch (B) {
j[a] = b.jgrid.htmlDecode(b(this).html())
}
});
if (c) {
i.push(j);
j = {}
}
}
k++
}
});
return i ? i : j
}
最后要在其中放置内部表的位置:
Finally where you want to put inner table do this:
<table>
<tr>
<td id="-1">
Now It's working!
</tr>
<td id="-1">
Yeah
</tr>
</tr>
</table>
当然您可以更改id
属性,但是由于jQuery针对class
属性的性能,我建议使用html id
属性修复此问题.
Of course you can change id
attribute but I recommend fix this with html id
attribute due to jQuery performance against class
attribute.
这篇关于jqGrid-带有TD元素的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!