Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by bigwill on Jun 15, 2009 06:43
open dhtmlx forum
DHTMLXTreeView

Hi all,

I am using the TreeView within my project but wondering what the best method is for the following:

- If a parent node is selected (and all the child nodes for that parent) i need to return the parent id only.
- If a some but not all child nodes are selected i need to return those individual child IDs instead of the Parent ID.

Is this possible with the current API or would i need to tweak this slightly?

Thanks very much, Great product!
Answer posted by Alex (support) on Jun 16, 2009 01:49

Hello, 

do you use 3-state checkboxes ?

if yes, you can use the following approach

function getChecked(id){
  var state = tree.isItemChecked(itemId)
  if(state==1) return id;
  if(state ==2){
  var arr = [];
  var ids = tree.getAllSubItems(id).split(",");
  for(var i=0; i < ids.length;i++){
  if(tree.isItemChecked(ids[i])==1)
  arr.push(ids[i]);
  }
  return arr
  }
}

if you don't use 3-state checkboxes, you can can use getAllSubItems(id) method in combination with isItemChecked method to get the necessary result.

Answer posted by bigwill on Jun 18, 2009 03:44
Hi,

Yes i am using a 3-state checkbox so that works perfectly.

Is there a method of knowing if the value returned is the id of a parent or child node?

Thank you.
Answer posted by Alex (support) on Jun 18, 2009 05:11

Hello,

there is hasChildren(itemId) method that returns the number of child nodes. So, it returns 0 for leaves and positive number for folders.