jqGrid treeGrid catch展开collaps事件 [英] jqGrid treeGrid catch expand collaps events

查看:1625
本文介绍了jqGrid treeGrid catch展开collaps事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jqGrid来处理一些大树。现在我想要记住Cookie中的展开和折叠的节点

I use jqGrid to epose some big Tree. Now I want to remember expanded and collapsed nodes in cookies

所以我想抓住expand和collaps事件。我在手动中找不到它

So I want to catch expand and collaps event. I couldn't find it in manual

所以我已经以这种方式解决了。

So I've resolved it in this way

grid.find("div.treeclick").bind("click",function(e){
    classes = $(this).attr('class');
    //returns:
    //ui-icon treeclick ui-icon-triangle-1-s tree-minus
    //ui-icon treeclick ui-icon-triangle-1-e tree-plus
    if(classes.indexOf('-minus') != -1)
        alert ('Expand!');
    else if(classes.indexOf('-plus') != -1)
        alert ('Collaps!')
});

任何人都可以提出另一种方式?

Could anybody propose another way?

推荐答案

jqGrid中目前没有事件或回调可以帮助您捕获树节点的折叠或展开。

There are currently no event or callback in the jqGrid which could help you to catch collapsing or expanding of the tree nodes.

一般你发布的代码做正确的测试。然而,你的自我不完全满意的解决方案。我发现它也不是那么好。我看到的最大的问题是,你测试哪个图标有按钮,但图标将由网格中相同事件的原始处理程序更改。绑定的顺序应该非常重要。

In general the code which you posted do correct tests. Nevertheless you self are not full satisfied by the solution. I find it also not so good. The most problem which I see is that you test which icon has the button, but the icon will be changed by the original handler of the same events in the grid. The the order of the bindings should be very important.

在你的地方,我喜欢在没有事件存在的情况下使用子类化技术。

On your place I prefer to use subclassing technique in such cases when no event exists. It's very easy, but it's 100% effective.

树网格有方法 expandNode collapseNode 已记录。在点击节点图标的情况下,jqGrid也会在内部调用该方法。 expandNode 调用 reloadGrid 显示扩展的树。

The Tree Grid has methods expandNode and collapseNode which are documented. The method will be called internally by jqGrid too in case of clicks on the node icon. The method expandNode calls reloadGrid to display the expanded tree.

因此我建议在树网格创建后添加以下代码:

So I suggest to add the following code after the Tree Grid is created:

var orgExpandNode = $.fn.jqGrid.expandNode,
    orgCollapseNode = $.fn.jqGrid.collapseNode;
$.jgrid.extend({
    expandNode: function (rc) {
        alert('before expandNode: rowid="' + rc._id_ + '", name="' + rc.name + '"');
        return orgExpandNode.call(this, rc);
    },
    collapseNode: function (rc) {
        alert('before collapseNode: rowid="' + rc._id_ + '", name="' + rc.name + '"');
        return orgCollapseNode.call(this, rc);
    }
});

您可以在演示

这篇关于jqGrid treeGrid catch展开collaps事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆