Skip to content

Commit e11d408

Browse files
committed
chore: polish example
1 parent 2a3612f commit e11d408

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

knowledge-base/treeview-disable-checkboxes.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ To disable checkboxes for specific TreeView items based on a condition, use the
5252
</TelerikTreeView>
5353
5454
<style>
55-
.disabled-checkbox .k-checkbox {
56-
opacity: 0.7;
55+
.@(DisabledCheckboxClass) .k-checkbox {
56+
opacity: 0.5;
5757
pointer-events: none;
5858
}
5959
60-
.disabled-checkbox .k-treeview-leaf {
60+
.@(DisabledCheckboxClass) .k-treeview-leaf {
6161
opacity: 0.7;
6262
pointer-events: none;
6363
}
@@ -67,13 +67,14 @@ To disable checkboxes for specific TreeView items based on a condition, use the
6767
private IEnumerable<TreeViewItem> FlatData { get; set; }
6868
private IEnumerable<object> CheckedItems { get; set; } = new List<object>();
6969
private IEnumerable<object> ExpandedItems { get; set; } = new List<TreeViewItem>();
70+
private string DisabledCheckboxClass { get; set; } = "disabled-checkbox";
7071
7172
private void HandleOnItemRender(TreeViewItemRenderEventArgs args)
7273
{
7374
var item = args.Item as TreeViewItem;
7475
if (!item.IsActive)
7576
{
76-
args.Class = "disabled-checkbox";
77+
args.Class = DisabledCheckboxClass;
7778
}
7879
}
7980
protected override void OnInitialized()
@@ -87,46 +88,46 @@ To disable checkboxes for specific TreeView items based on a condition, use the
8788
List<TreeViewItem> items = new List<TreeViewItem>();
8889
8990
items.Add(new TreeViewItem()
90-
{
91-
Id = 1,
92-
Text = "Root",
93-
ParentIdValue = null,
94-
HasChildren = true,
95-
Icon = SvgIcon.Folder,
96-
IsChecked = false,
97-
IsActive = true
98-
});
91+
{
92+
Id = 1,
93+
Text = "Root",
94+
ParentIdValue = null,
95+
HasChildren = true,
96+
Icon = SvgIcon.Folder,
97+
IsChecked = false,
98+
IsActive = true
99+
});
99100
100101
Random rnd = new Random();
101102
for (int i = 2; i <= 5; i++)
102103
{
103104
bool hasChildren = rnd.Next(0, 2) == 1;
104105
items.Add(new TreeViewItem()
105-
{
106-
Id = i,
107-
Text = $"Folder {i}",
108-
ParentIdValue = 1,
109-
HasChildren = hasChildren,
110-
Icon = hasChildren ? SvgIcon.Folder : SvgIcon.File,
111-
IsChecked = false,
112-
IsActive = rnd.Next(0, 2) == 1
113-
});
106+
{
107+
Id = i,
108+
Text = $"Folder {i}",
109+
ParentIdValue = 1,
110+
HasChildren = hasChildren,
111+
Icon = hasChildren ? SvgIcon.Folder : SvgIcon.File,
112+
IsChecked = false,
113+
IsActive = rnd.Next(0, 2) == 1
114+
});
114115
115116
if (hasChildren)
116117
{
117118
for (int j = 1; j <= rnd.Next(1, 4); j++)
118119
{
119120
int childId = i * 10 + j;
120121
items.Add(new TreeViewItem()
121-
{
122-
Id = childId,
123-
Text = $"File {childId}",
124-
ParentIdValue = i,
125-
HasChildren = false,
126-
Icon = SvgIcon.File,
127-
IsChecked = false,
128-
IsActive = rnd.Next(0, 2) == 1
129-
});
122+
{
123+
Id = childId,
124+
Text = $"File {childId}",
125+
ParentIdValue = i,
126+
HasChildren = false,
127+
Icon = SvgIcon.File,
128+
IsChecked = false,
129+
IsActive = rnd.Next(0, 2) == 1
130+
});
130131
}
131132
}
132133
}
@@ -137,10 +138,10 @@ To disable checkboxes for specific TreeView items based on a condition, use the
137138
public class TreeViewItem
138139
{
139140
public int Id { get; set; }
140-
public string Text { get; set; }
141+
public string Text { get; set; } = string.Empty;
141142
public int? ParentIdValue { get; set; }
142143
public bool HasChildren { get; set; }
143-
public ISvgIcon Icon { get; set; }
144+
public ISvgIcon? Icon { get; set; }
144145
public bool IsChecked { get; set; }
145146
public bool IsActive { get; set; }
146147
}

0 commit comments

Comments
 (0)