Welcome Guest Search | Active Topics | Sign In | Register

JQuery and the EO.Web Treeview control Options
Duane
Posted: Monday, February 1, 2010 12:00:05 PM
Rank: Newbie
Groups: Member

Joined: 2/1/2010
Posts: 5
Hi ... I have four treeviews on a page. Each treeview is uniquely named and each has checkboxes.
I also have four buttons ... the buttons hide and show each treeview respectively. What I want to happen is (on the client-side):

if the user clicks button one then all checked nodes of treeviews 2-4 are unchecked. So I guess what I'm asking is: How to you programmatically uncheck all nodes of a given treeview?

Preferably I would like to use jquery to do this but I'll settle for plain ole javascript.

Thanks in advance .......

eo_support
Posted: Monday, February 1, 2010 12:16:08 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You will need to use our client side JavaScript API to do it. This is the function you will need to call:

http://doc.essentialobjects.com/library/1/jsdoc.public.treenode.setcheckstate.aspx

In order to call this function, you need to get a reference of the client side TreeNode object, you can do that by first getting a reference of the TreeView object and then call various methods on the TreeView to get the TreeNode object you want to check/uncheck. For example, the following code checks the first root node:

Code: JavaScript
//Get the TreeView object
var tv = eo_GetObject("TreeView1");

//Get the top "Group" object, which represents all nodes within
//a single parent node 
var topGroup = tv.getTopGroup();

//Get the first node in the group
var firstItem = topGroup.getItemByIndex(0);

//Check the node
firstItem.setCheckState(1);


You can go over this topic to get a basic idea of how to use our client side API:

http://doc.essentialobjects.com/library/1/clientapi_howto.aspx

You will aslo need to go over the reference section (especially "JavaScript Objects" section) to see what objects and functions are available to you. The code above demonstrates how to check a single node. In order to check/uncheck all nodes in a TreeView, you need to write a recursive function to do it.

You can not do it with JQuery because a lot of our internal data needs to be updated when you update the checkbox. Thus you can only do it through our API.

Please feel free to let us know if you have any more questions.

Thanks!
Duane
Posted: Monday, February 1, 2010 12:28:21 PM
Rank: Newbie
Groups: Member

Joined: 2/1/2010
Posts: 5
Thanks ... I've been banging my head against the wall for a while about this. So ... if I have AutoUncheckChildren="true" then simply implementing the code you provided with "firstItem.setCheckState(0);" should do the trick, right?


eo_support
Posted: Monday, February 1, 2010 12:36:35 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
I don't think you can get away from the recursive function. :) I believe AutoUncheckChildren is only for when user actually clicks the checkbox. It is ignored when you do it through code.

Thanks
Duane
Posted: Monday, February 1, 2010 1:02:50 PM
Rank: Newbie
Groups: Member

Joined: 2/1/2010
Posts: 5
I believe in most cases you are correct but for my situation it seems that simply setting the firstItem to checked (which will check all children ... the whole tree) and then immediately setting it to unchecked (unchecks all children .. the whole tree) seems to be working.

Such as this:

var tv = eo_GetObject("tv_central");
var topGroup = tv.getTopGroup();
var firstItem = topGroup.getItemByIndex(0);
firstItem.setCheckState(1); //check
firstItem.setCheckState(0); //uncheck


Thanks for answering so quickly ... my response I've ever had on a forum.
eo_support
Posted: Monday, February 1, 2010 1:24:49 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Ah. That's interesting. Glad that it's working for you but it goes against what we knew. :) We will look into it to get our memory updated then.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.