I have a treeview. And there is too much white space between the nodes. How can I control this?
I have included a screenshot so you see what I mean.
1 Answer, 1 is accepted
1
Accepted
Marin Bratanov
Telerik team
answered on 15 Jun 2021, 05:30 PM
Hello David,
You can use CSS to target the treeview nodes and decrease the default paddings they have in our stylesheet (or rules coming from site-specific stylesheets, because the screenshot feels a bit too large for our built-in designs). You can see where those rules come from by inspecting the rendered HTML and its CSS rules (see here for an example).
Here's also one code snippet I made for you with that approach that showcases the concept:
<style>
.small-spacing.k-treeview.k-in {
padding: 0;
/*note that in your case the CSS rule may be different and may have to target a different element*/
}
</style>
<TelerikTreeViewData="@FlatData" Class="small-spacing">
<TreeViewBindings>
<TreeViewBinding IdField="Id" ParentIdField="ParentIdValue" ExpandedField="Expanded" TextField="Text" HasChildrenField="HasChildren" IconField="Icon" />
</TreeViewBindings>
</TelerikTreeView>
@code {
publicclassTreeItem
{
public int Id { get; set; }
publicstringText { get; set; }
publicint? ParentIdValue { get; set; }
publicboolHasChildren { get; set; }
publicstringIcon { get; set; }
publicboolExpanded { get; set; }
}
publicIEnumerable<TreeItem> FlatData { get; set; }
protectedoverridevoidOnInitialized()
{
LoadFlatData();
}
privatevoidLoadFlatData()
{
List<TreeItem> items = new List<TreeItem>();
items.Add(new TreeItem()
{
Id = 1,
Text = "Project",
ParentIdValue = null,
HasChildren = true,
Icon = "folder",
Expanded = true
});
items.Add(newTreeItem()
{
Id = 2,
Text = "Design",
ParentIdValue = 1,
HasChildren = true,
Icon = "brush",
Expanded = true
});
items.Add(newTreeItem()
{
Id = 3,
Text = "Implementation",
ParentIdValue = 1,
HasChildren = true,
Icon = "folder",
Expanded = true
});
items.Add(newTreeItem()
{
Id = 4,
Text = "site.psd",
ParentIdValue = 2,
HasChildren = false,
Icon = "psd",
Expanded = true
});
items.Add(newTreeItem()
{
Id = 5,
Text = "index.js",
ParentIdValue = 3,
HasChildren = false,
Icon = "js"
});
items.Add(newTreeItem()
{
Id = 6,
Text = "index.html",
ParentIdValue = 3,
HasChildren = false,
Icon = "html"
});
items.Add(newTreeItem()
{
Id = 7,
Text = "styles.css",
ParentIdValue = 3,
HasChildren = false,
Icon = "css"
});
FlatData = items;
}
}
Regards,
Marin Bratanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.