You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: components/treeview/checkboxes/overview.md
+128-1Lines changed: 128 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -584,7 +584,7 @@ You can allow the user to click on the node itself and the TreeView will automat
584
584
585
585
You can combine both selection and checking nodes. To keep both collections in sync you can assign the same collection to both `SelectedItems` and `CheckedItems` as demonstrated in the example below.
586
586
587
-
````CSHTML
587
+
````Single
588
588
@* You can couple checking the item and placing it in the selected item list. *@
589
589
590
590
<TelerikTreeView Data="@FlatData"
@@ -608,6 +608,133 @@ You can combine both selection and checking nodes. To keep both collections in s
608
608
</div>
609
609
610
610
611
+
@code {
612
+
613
+
public IEnumerable<object> checkedItems { get; set; } = new List<object>();
614
+
615
+
public class TreeItem
616
+
{
617
+
public int Id { get; set; }
618
+
public string Text { get; set; }
619
+
public int? ParentIdValue { get; set; }
620
+
public bool HasChildren { get; set; }
621
+
public string Icon { get; set; }
622
+
public bool Expanded { get; set; }
623
+
}
624
+
625
+
public IEnumerable<TreeItem> FlatData { get; set; }
626
+
627
+
protected override void OnInitialized()
628
+
{
629
+
LoadFlatData();
630
+
631
+
var precheckedItem = FlatData.Where(x => x.Id == 3); // provide initial checked item when the page is loaded
632
+
633
+
checkedItems = new List<object>(precheckedItem);
634
+
}
635
+
636
+
private void LoadFlatData()
637
+
{
638
+
List<TreeItem> items = new List<TreeItem>();
639
+
640
+
items.Add(new TreeItem()
641
+
{
642
+
Id = 1,
643
+
Text = "Project",
644
+
ParentIdValue = null,
645
+
HasChildren = true,
646
+
Icon = "folder",
647
+
Expanded = true
648
+
});
649
+
650
+
items.Add(new TreeItem()
651
+
{
652
+
Id = 2,
653
+
Text = "Design",
654
+
ParentIdValue = 1,
655
+
HasChildren = true,
656
+
Icon = "brush",
657
+
Expanded = true
658
+
});
659
+
items.Add(new TreeItem()
660
+
{
661
+
Id = 3,
662
+
Text = "Implementation",
663
+
ParentIdValue = 1,
664
+
HasChildren = true,
665
+
Icon = "folder",
666
+
Expanded = true
667
+
});
668
+
669
+
items.Add(new TreeItem()
670
+
{
671
+
Id = 4,
672
+
Text = "site.psd",
673
+
ParentIdValue = 2,
674
+
HasChildren = false,
675
+
Icon = "psd",
676
+
Expanded = true
677
+
});
678
+
items.Add(new TreeItem()
679
+
{
680
+
Id = 5,
681
+
Text = "index.js",
682
+
ParentIdValue = 3,
683
+
HasChildren = false,
684
+
Icon = "js"
685
+
});
686
+
items.Add(new TreeItem()
687
+
{
688
+
Id = 6,
689
+
Text = "index.html",
690
+
ParentIdValue = 3,
691
+
HasChildren = false,
692
+
Icon = "html"
693
+
});
694
+
items.Add(new TreeItem()
695
+
{
696
+
Id = 7,
697
+
Text = "styles.css",
698
+
ParentIdValue = 3,
699
+
HasChildren = false,
700
+
Icon = "css"
701
+
});
702
+
703
+
FlatData = items;
704
+
}
705
+
}
706
+
````
707
+
````Multiple
708
+
@* To select and check multiple items change both modes to Multiple *@
0 commit comments