mirror of
https://github.com/radzenhq/radzen-blazor.git
synced 2026-02-04 05:35:44 +00:00
121 lines
4.0 KiB
C#
121 lines
4.0 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using System;
|
|
|
|
namespace Radzen.Blazor
|
|
{
|
|
/// <summary>
|
|
/// Configures a level of nodes in a <see cref="RadzenTree" /> during data-binding.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// <RadzenTree Data=@rootEmployees>
|
|
/// <RadzenTreeLevel TextProperty="LastName" ChildrenProperty="Employees1" HasChildren=@(e => (e as Employee).Employees1.Any()) />
|
|
/// </RadzenTree>
|
|
/// @code {
|
|
/// IEnumerable<Employee> rootEmployees;
|
|
/// protected override void OnInitialized()
|
|
/// {
|
|
/// rootEmployees = NorthwindDbContext.Employees.Where(e => e.ReportsTo == null);
|
|
/// }
|
|
/// }
|
|
/// </code>
|
|
/// </example>
|
|
public class RadzenTreeLevel : ComponentBase
|
|
{
|
|
/// <summary>
|
|
/// Specifies the name of the property which provides values for the <see cref="RadzenTreeItem.Text" /> property of the child items.
|
|
/// </summary>
|
|
[Parameter]
|
|
public string? TextProperty { get; set; }
|
|
|
|
/// <summary>
|
|
/// Specifies the name of the property which provides values for the <see cref="RadzenTreeItem.Checkable" /> property of the child items.
|
|
/// </summary>
|
|
[Parameter]
|
|
public string? CheckableProperty { get; set; }
|
|
|
|
/// <summary>
|
|
/// Specifies the name of the property which returns child data. The value returned by that property should be IEnumerable
|
|
/// </summary>
|
|
[Parameter]
|
|
public string? ChildrenProperty { get; set; }
|
|
|
|
/// <summary>
|
|
/// Determines if a child item has children or not. Set to <c>value => true</c> by default.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// <RadzenTreeLevel HasChildren=@(e => (e as Employee).Employees1.Any()) />
|
|
/// </code>
|
|
/// </example>
|
|
[Parameter]
|
|
public Func<object, bool>? HasChildren { get; set; } = value => true;
|
|
|
|
/// <summary>
|
|
/// Determines if a child item is expanded or not. Set to <c>value => false</c> by default.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// <RadzenTreeLevel Expanded=@(e => (e as Employee).Employees1.Any()) />
|
|
/// </code>
|
|
/// </example>
|
|
[Parameter]
|
|
public Func<object, bool>? Expanded { get; set; } = value => false;
|
|
|
|
/// <summary>
|
|
/// Determines if a child item is selected or not. Set to <c>value => false</c> by default.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// <RadzenTreeLevel Selected=@(e => (e as Employee).LastName == "Fuller") />
|
|
/// </code>
|
|
/// </example>
|
|
[Parameter]
|
|
public Func<object, bool>? Selected { get; set; } = value => false;
|
|
|
|
/// <summary>
|
|
/// Determines the text of a child item.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// <RadzenTreeLevel Text=@(e => (e as Employee).LastName) />
|
|
/// </code>
|
|
/// </example>
|
|
[Parameter]
|
|
public Func<object, string>? Text { get; set; }
|
|
|
|
/// <summary>
|
|
/// Determines the if the checkbox of the child item can be checked.
|
|
/// </summary>
|
|
/// <example>
|
|
/// <code>
|
|
/// <RadzenTreeLevel Checkable=@(e => (e as Employee).LastName != null) />
|
|
/// </code>
|
|
/// </example>
|
|
[Parameter]
|
|
public Func<object, bool>? Checkable { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets or sets the template.
|
|
/// </summary>
|
|
[Parameter]
|
|
public RenderFragment<RadzenTreeItem>? Template { get; set; }
|
|
|
|
private RadzenTree? _tree;
|
|
|
|
/// <summary>
|
|
/// The RadzenTree which this item is part of.
|
|
/// </summary>
|
|
[CascadingParameter]
|
|
public RadzenTree? Tree
|
|
{
|
|
get => _tree;
|
|
set
|
|
{
|
|
if (value != null)
|
|
value.AddLevel(this);
|
|
_tree = value;
|
|
}
|
|
}
|
|
}
|
|
} |