From 93d1e8604ac1be886fea63b0ab355dfafce6cf5b Mon Sep 17 00:00:00 2001 From: Vladimir Enchev Date: Fri, 6 Dec 2024 10:36:26 +0200 Subject: [PATCH] PickList ItemRender event added --- Radzen.Blazor/Common.cs | 31 ++++++++++++++++-- Radzen.Blazor/RadzenPickList.razor | 4 +-- Radzen.Blazor/RadzenPickList.razor.cs | 33 ++++++++++++++++++++ RadzenBlazorDemos/Pages/PickListConfig.razor | 26 +++++++++------ 4 files changed, 79 insertions(+), 15 deletions(-) diff --git a/Radzen.Blazor/Common.cs b/Radzen.Blazor/Common.cs index 70f2ebb206e..f8b09cb6fbe 100644 --- a/Radzen.Blazor/Common.cs +++ b/Radzen.Blazor/Common.cs @@ -557,7 +557,6 @@ public class RadzenDropZoneItemRenderEventArgs /// Gets or sets a value indicating whether this item is visible. /// /// true if visible; otherwise, false. - [Parameter] public bool Visible { get; set; } = true; /// @@ -580,14 +579,12 @@ public class DropDownBaseItemRenderEventArgs /// Gets or sets a value indicating whether this item is visible. /// /// true if visible; otherwise, false. - [Parameter] public bool Visible { get; set; } = true; /// /// Gets or sets a value indicating whether this item is visible. /// /// true if visible; otherwise, false. - [Parameter] public bool Disabled { get; set; } /// @@ -618,6 +615,34 @@ public class ListBoxItemRenderEventArgs : DropDownBaseItemRenderEventArg public RadzenListBox ListBox { get; internal set; } } + /// + /// Supplies information about RadzenPickList ItemRender event. + /// + public class PickListItemRenderEventArgs + { + /// + /// Gets the data item. + /// + public TItem Item { get; internal set; } + + /// + /// Gets or sets a value indicating whether this item is visible. + /// + /// true if visible; otherwise, false. + public bool Visible { get; set; } = true; + + /// + /// Gets or sets a value indicating whether this item is visible. + /// + /// true if visible; otherwise, false. + public bool Disabled { get; set; } + + /// + /// Gets or sets the row HTML attributes. + /// + public IDictionary Attributes { get; private set; } = new Dictionary(); + } + /// /// Supplies information about a event that is being raised. /// diff --git a/Radzen.Blazor/RadzenPickList.razor b/Radzen.Blazor/RadzenPickList.razor index 25a299993c6..c17928dd6fe 100644 --- a/Radzen.Blazor/RadzenPickList.razor +++ b/Radzen.Blazor/RadzenPickList.razor @@ -13,7 +13,7 @@ } @@ -35,7 +35,7 @@ } diff --git a/Radzen.Blazor/RadzenPickList.razor.cs b/Radzen.Blazor/RadzenPickList.razor.cs index 71de5d6d5c3..d2091d6dcce 100644 --- a/Radzen.Blazor/RadzenPickList.razor.cs +++ b/Radzen.Blazor/RadzenPickList.razor.cs @@ -98,6 +98,39 @@ public partial class RadzenPickList : RadzenComponent [Parameter] public RenderFragment Template { get; set; } + /// + /// Gets or sets the row render callback. Use it to set row attributes. + /// + /// The row render callback. + [Parameter] + public Action> ItemRender { get; set; } + + void OnSourceItemRender(ListBoxItemRenderEventArgs args) + { + if (ItemRender != null) + { + var newArgs = new PickListItemRenderEventArgs(); + newArgs.Item = args.Item != null ? (TItem)args.Item : default(TItem); + ItemRender(newArgs); + newArgs.Attributes.ToList().ForEach(k => args.Attributes.Add(k.Key, k.Value)); + args.Visible = newArgs.Visible; + args.Disabled = newArgs.Disabled; + } + } + + void OnTargetItemRender(ListBoxItemRenderEventArgs args) + { + if (ItemRender != null) + { + var newArgs = new PickListItemRenderEventArgs(); + newArgs.Item = args.Item != null ? (TItem)args.Item : default(TItem); + ItemRender(newArgs); + newArgs.Attributes.ToList().ForEach(k => args.Attributes.Add(k.Key, k.Value)); + args.Visible = newArgs.Visible; + args.Disabled = newArgs.Disabled; + } + } + private RenderFragment ListBoxTemplate => Template != null ? item => Template((TItem)item) : null; /// diff --git a/RadzenBlazorDemos/Pages/PickListConfig.razor b/RadzenBlazorDemos/Pages/PickListConfig.razor index 7c5971b94c6..1731a98668a 100644 --- a/RadzenBlazorDemos/Pages/PickListConfig.razor +++ b/RadzenBlazorDemos/Pages/PickListConfig.razor @@ -76,16 +76,17 @@ - - Customers: - - - Selected Customers: - - + ButtonGap="@gap" ButtonJustifyContent="@justifyContent" ButtonStyle="@style" ButtonSize="@size" ButtonShade="@shade" ButtonVariant="@variant" + ItemRender="OnItemRender"> + + Customers: + + + Selected Customers: + + @@ -149,4 +150,9 @@ Source = dbContext.Customers; } + + void OnItemRender(PickListItemRenderEventArgs args) + { + args.Disabled = args.Item.CompanyName.Contains("a"); + } } \ No newline at end of file