We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Using HierarchicalDataTemplate with SfTreeGrid

Hello,

I'm used to work with TreeView in WPF and typically, when you need to have specific behavior for different nodes (for exemple, a folder, a file), you can use HierarchicalDataTemplate. It also seemed to be the case with syncfusion.treeviewadv. But I can't find how to set it up on SfTreeGrid. In TreeViewAdv, you can use syncfusion:TreeViewAdv.ItemTemplate but it's nowhere to be found in SFTreeGrid. Is it supported? 

I've seen the IValueConverter, but I wasn't sure if it was intended as a full replacement for datatemplate.

Thanks,

Mathieu

7 Replies

SR Sivakumar R Syncfusion Team January 17, 2017 06:11 AM UTC

Hi Mathieu, 
 
SfTreeGrid is a column based on control where on row will have multiple cells and TreView is a row based control where it has only single column. 
 
So, SfTreeGrid provides ways to customize or load template on column basics.  
 
Refer the below documentation link which explains how to generate columns and different columns supportted. 
 
You can use TreeGridColumn.CellTemplate or TreeGridColumn.CellTemplateSelector to achieve your requirement. 
 
Thanks, 
Sivakumar 



MB Mathieu Belanger January 18, 2017 02:14 AM UTC

Thanks for the quick answer. I'll have a look.


AP Ashwini Paranthaman Syncfusion Team January 18, 2017 06:55 AM UTC

Hi Mathieu, 
Thank you for the update. 
We will wait to hear from you. 
Regards, 
Ashwini P. 



MB Mathieu Belanger January 20, 2017 11:33 PM UTC

Hello,

Sorry for my late answer. I've been able to make it work properly using CellTemplateSelector. I can now have custom cell look and feel and custom context menu depending on my type of item.

However, it doesn't help with the fact that using hierarchicalDataTemplate, I was able to specify an itemsource pointing to my MVVM. And when I was adding or removing a item to my model, it was automatically added to the tree which is not the case with sftreegrid. I've not find the best way to use TreeBehavior properly modify the content of my viewmodel without having to directly call the sftreegrid. Is it possible to do it?

Thanks again


MK Muthukumar Kalyanasundaram Syncfusion Team January 24, 2017 02:29 AM UTC

Hi Mathieu,  

Thanks for the update. 
  
We couldn’t get your requirement clearly. So, we created the sample based on our understanding. On below attached sample, we have added or removed item in collection at run time using commands. If the data source implements INotifyCollectionChanged interface, then SfTreeGrid control will automatically refresh the UI when item is added, removed or while list cleared. If your requirement is different from this, could you please explain your requirement clearly? This would be more helpful for us to proceed further.    
  
  
Please let us know if you have any concern. 

Regards, 
Muthukumar K 



MB Mathieu Belanger January 25, 2017 02:30 AM UTC

Hi,

Thanks you for your support, it is really appreciated. I've taken a look at your sample and it helped me simplify my code. I was trying to port something complex to the treegrid. I decided to get rid of load on demand to load everything straight to memory and I've been able to make everything work. I'll be able to build on that for now on.

Thanks again,

Mathieu


AP Ashwini Paranthaman Syncfusion Team January 25, 2017 10:31 AM UTC

Hi Mathieu, 
Thank you for the feedback. 
We are glad that your requirement has been met. 
Please let us know if you need any other assistance. 
Regards, 
Ashwini P. 


Loader.
Up arrow icon