0

How to get tree selected item?

asked 2007-12-04 15:30:29 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4658311

By: tommasofin

If I handle the onSelect event for a Tree componet I can retrieve the selected items with tree.getSelectedItems().

I need to get the last selected item (the one who fired the event). There is a way to get that in ZK?

Unfortunately tree.getSelectItem() give me only a random selected item, not the one I click...

delete flag offensive retag edit

8 Replies

Sort by ยป oldest newest

answered 2007-12-06 00:58:39 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4661208

By: jebberwocky

Dear tommaso

I tried that tree.getSelectedItem(). I gives the one I click on.
Testing cod:

<window title="tree demo" border="normal">
<tree id="tree" width="90%" rows="5">
<treecols sizable="true">
<treecol label="Name"/>
<treecol label="Description"/>
</treecols>
<treechildren>
<treeitem id="t1">
<treerow>
<treecell label="Item 1"/>
<treecell label="Item 1 description"/>
</treerow>
</treeitem>
<treeitem id="t2">
<treerow>
<treecell label="Item 2"/>
<treecell label="Item 2 description"/>
</treerow>
</treeitem>
<treeitem id="t3" label="Item 3"/>
</treechildren>
</tree>
<button>
<attribute name="onClick" >
alert(tree.getSelectedItem().getId());
</attribute>
</button>
</window>


Could you provide your code?

link publish delete flag offensive edit

answered 2007-12-06 08:32:47 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4661568

By: tommasofin

Hi,
the problem is when you have a tree with multiple selection. You will never know which treeitem is the last selected/deselected, because the tree.getSelectedItem() always return the first selected item. This is a ZK limit because you can't handle the onClick event of treeitem, treerow, treecell...
Try this:

<window title="tree demo" border="normal"> <tree checkmark="true" multiple="true" id="tree" width="90%" rows="5"> <attribute name="onSelect" > alert(self.getSelectedItem().getId());
</attribute>
<treecols sizable="true">
<treecol label="Name"/>
<treecol label="Description"/>
</treecols>
<treechildren>
<treeitem id="t1">
<treerow>
<treecell label="Item 1"/>
<treecell label="Item 1 description"/>
</treerow>
</treeitem>
<treeitem id="t2">
<treerow>
<treecell label="Item 2"/>
<treecell label="Item 2 description"/>
</treerow>
</treeitem>
<treeitem id="t3" label="Item 3"/>
</treechildren>
</tree>
</window>

link publish delete flag offensive edit

answered 2007-12-06 09:32:37 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4661619

By: henrichen

May be you can try something like following:

Set current = tree.getSelectedItems();
Set newSelect = current.removeAll(prev); Set prev = current;

Regarding the issue of getSelectedItem() always returning the first one, we follow the spec. of other window systems with multiple selection :)

/henri

link publish delete flag offensive edit

answered 2007-12-06 09:40:22 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4661631

By: henrichen

If you really needs this, please post to feature request. Maybe we can add in SelectEvent a getClickedItem() that will return the last clicked item?

/henri

link publish delete flag offensive edit

answered 2007-12-06 10:15:01 +0800

admin gravatar image admin
18691 1 10 129
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=4661668

By: tommasofin

Ok thanks, I need this because I would like to make a tree that when you select a node propagate the selection in all the node's childrens. You should think to add this mold in the standard tree component too.

link publish delete flag offensive edit

answered 2016-10-04 08:23:59 +0800

vsansone gravatar image vsansone
1 1

Hi,

I have a similar problem. Have you found a solution to get last selected item with multiple selection?

I have found a solution to iterate on selecteditems and get last item; I verified this method get last selected item, but I'm not secure to have always last item.

link publish delete flag offensive edit

answered 2016-10-06 15:53:53 +0800

Darksu gravatar image Darksu
1991 1 4

Hello vsansone,

I believe it should work.

Best Regards,

Darksu

link publish delete flag offensive edit

answered 2016-10-08 07:39:58 +0800

phamtuanktdt gravatar image phamtuanktdt flag of Viet Nam
1
http://narwhale-io.com/

Thank you. I get what I need now

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2007-12-04 15:30:29 +0800

Seen: 644 times

Last updated: Oct 08 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More