I am trying to capture the click event of a treegrid leaf node in order to trigger a refresh of another instance of a free-jqGrid gridview. I am using free-jqGrid 4.13.2. I have looked at the source code for the treegrid, but I don't see a function that fires when the leaf node is clicked.
I have tried using a custom formatter in the gridview, replacing the cellvalue with a div with an onclick event that will refresh the gridview. It works the first time (it refreshes the gridview), but after that, it does not and the only thing I see is the icons in the gridview toolbar are duplicating with each click of the treegrid leaf node.
答案 0 :(得分:1)
树jqGrid对TreeGrid节点有许多回调,但是叶子将被解释为带有数据的简单行。因此,您必须使用beforeSelectRow
,onCellSelect
或onSelectRow
来检测所需的点击。回调具有rowid
作为第一个参数,您可以使用getLocalRow
根据rowid
获取行的数据。相应的代码将非常简单:
beforeSelectRow: function (rowid, e) {
var item = $(this).jqGrid("getLocalRow", rowid);
if (item != null && item.isLeaf) {
alert("The row with leaf \"" + item.name + "\" is clicked");
}
return true; // allow row selection
}
The demo演示了代码。您可以使用e.target
获取有关已点击单元格的更准确信息。例如$(e.target).closest("tr.jqgrow>td")
将为您点击<td>
单元格的DOM元素提供jQuery包装。