Skip to content

Commit

Permalink
PickList ItemRender event added
Browse files Browse the repository at this point in the history
  • Loading branch information
enchev committed Dec 6, 2024
1 parent 53d32db commit 93d1e86
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 15 deletions.
31 changes: 28 additions & 3 deletions Radzen.Blazor/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,6 @@ public class RadzenDropZoneItemRenderEventArgs<TItem>
/// Gets or sets a value indicating whether this item is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
[Parameter]
public bool Visible { get; set; } = true;

/// <summary>
Expand All @@ -580,14 +579,12 @@ public class DropDownBaseItemRenderEventArgs<TValue>
/// Gets or sets a value indicating whether this item is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
[Parameter]
public bool Visible { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether this item is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
[Parameter]
public bool Disabled { get; set; }

/// <summary>
Expand Down Expand Up @@ -618,6 +615,34 @@ public class ListBoxItemRenderEventArgs<TValue> : DropDownBaseItemRenderEventArg
public RadzenListBox<TValue> ListBox { get; internal set; }
}

/// <summary>
/// Supplies information about RadzenPickList ItemRender event.
/// </summary>
public class PickListItemRenderEventArgs<TItem>
{
/// <summary>
/// Gets the data item.
/// </summary>
public TItem Item { get; internal set; }

/// <summary>
/// Gets or sets a value indicating whether this item is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
public bool Visible { get; set; } = true;

/// <summary>
/// Gets or sets a value indicating whether this item is visible.
/// </summary>
/// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
public bool Disabled { get; set; }

/// <summary>
/// Gets or sets the row HTML attributes.
/// </summary>
public IDictionary<string, object> Attributes { get; private set; } = new Dictionary<string, object>();
}

/// <summary>
/// Supplies information about a <see cref="RadzenDatePicker{TValue}.DateRender" /> event that is being raised.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions Radzen.Blazor/RadzenPickList.razor
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
<RadzenListBox @bind-Value=@selectedSourceItems Data="@source" Multiple="@Multiple" @bind-SearchText=@sourceSearchText
FilterAsYouType=true FilterCaseSensitivity=FilterCaseSensitivity.CaseInsensitive
TextProperty="@TextProperty" AllowFiltering=@AllowFiltering
TextProperty="@TextProperty" AllowFiltering=@AllowFiltering ItemRender="@OnSourceItemRender"
Template=@ListBoxTemplate Placeholder="@(SourcePlaceholder ?? Placeholder)"
Disabled=@(Disabled || Source == null || (Source != null && !Source.Any()))
/>
Expand All @@ -35,7 +35,7 @@
}
<RadzenListBox @bind-Value=@selectedTargetItems Data="@target" Multiple="@Multiple" @bind-SearchText=@targetSearchText
FilterAsYouType=true FilterCaseSensitivity=FilterCaseSensitivity.CaseInsensitive
TextProperty="@TextProperty" AllowFiltering=@AllowFiltering
TextProperty="@TextProperty" AllowFiltering=@AllowFiltering ItemRender="@OnTargetItemRender"
Template=@ListBoxTemplate Placeholder="@(TargetPlaceholder ?? Placeholder)"
Disabled=@(Disabled || Target == null|| (Target != null && !Target.Any()))
/>
Expand Down
33 changes: 33 additions & 0 deletions Radzen.Blazor/RadzenPickList.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,39 @@ public partial class RadzenPickList<TItem> : RadzenComponent
[Parameter]
public RenderFragment<TItem> Template { get; set; }

/// <summary>
/// Gets or sets the row render callback. Use it to set row attributes.
/// </summary>
/// <value>The row render callback.</value>
[Parameter]
public Action<PickListItemRenderEventArgs<TItem>> ItemRender { get; set; }

void OnSourceItemRender(ListBoxItemRenderEventArgs<object> args)
{
if (ItemRender != null)
{
var newArgs = new PickListItemRenderEventArgs<TItem>();
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<object> args)
{
if (ItemRender != null)
{
var newArgs = new PickListItemRenderEventArgs<TItem>();
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<dynamic> ListBoxTemplate => Template != null ? item => Template((TItem)item) : null;

/// <summary>
Expand Down
26 changes: 16 additions & 10 deletions RadzenBlazorDemos/Pages/PickListConfig.razor
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@
<RadzenCard>
<RadzenPickList AllowMoveAll="@allowMoveAll" AllowMoveAllSourceToTarget="@allowMoveSourceToTarget" AllowMoveAllTargetToSource="@allowMoveTargetToSource" @bind-Source="@Source" @bind-Target="@Target" Style="height:500px; width:100%;" Orientation="@orientation"
TextProperty="@nameof(Customer.CompanyName)" AllowFiltering="@allowFilter" Multiple="@multiple" ShowHeader="@showHeader" Disabled="@disabled"
ButtonGap="@gap" ButtonJustifyContent="@justifyContent" ButtonStyle="@style" ButtonSize="@size" ButtonShade="@shade" ButtonVariant="@variant">
<SourceHeader>
Customers:
</SourceHeader>
<TargetHeader>
Selected Customers:
</TargetHeader>
<Template>
Company: @context.CompanyName
</Template>
ButtonGap="@gap" ButtonJustifyContent="@justifyContent" ButtonStyle="@style" ButtonSize="@size" ButtonShade="@shade" ButtonVariant="@variant"
ItemRender="OnItemRender">
<SourceHeader>
Customers:
</SourceHeader>
<TargetHeader>
Selected Customers:
</TargetHeader>
<Template>
Company: @context.CompanyName
</Template>
</RadzenPickList>
</RadzenCard>
</RadzenStack>
Expand Down Expand Up @@ -149,4 +150,9 @@

Source = dbContext.Customers;
}

void OnItemRender(PickListItemRenderEventArgs<Customer> args)
{
args.Disabled = args.Item.CompanyName.Contains("a");
}
}

0 comments on commit 93d1e86

Please sign in to comment.