Detect if current item has children

I am trying to format my text based on whether or not the current item has children. How can I detect this? For example, if the item that is being rendered does not have children, then I would like to add an additional link to the box.

I’m assuming that this could be handled using the following, but I’m not sure how to use it in the box template code.
{{subordinatesCount pochContext.needSubordinatesCount}}

Thank you!

Dan

This is a solution for Org Chart 3. Check the reply for Org Chart 4 here.

Hi @SPMan,

Thank you for your question.

It's not possible to find items with no subordinates through the number of subordinates mechanism. This feature loads dynamically, thus it's not possible get the value in the onBoxRendered event.

But you can do it like this:

renderer.onBoxRendered(function(event, box, itemData){
  var itemWrap = box.$elem.closest(".poch-item-wrap");
  
  if(!itemWrap.hasClass("poch-with-subordinates"))
  {
  	box.$elem.addClass("custom-class");
  }

});

So, now items without subordinates have a custom class. You can hide the link by default and display it for the boxes with the custom class only.

Anna Dorokhova
Plumsail Team

Hi Anna,
Thank you for the reply. This will work perfectly.
Dan

1 Like

Update for Org Chart 4 was published in this topic.