Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Passing parameter in mudtable

$
0
0

I have 3 components one MainComponent (Test.razor) consuming theParent Component(ParentComponent.com) and ChildComponent.

ChildComponent.razor

<MudTd DataLabel="Select"><MudCheckBox T="bool" Value="@GetIsSelected(context)" ValueChanged="@(e => ToggleExpansion(context))"></MudCheckBox></MudTd>            @foreach (var property in typeof(TItem).GetProperties()){if (property.GetCustomAttributes(typeof(DisplayAttribute), false).Length > 0){<MudTd DataLabel="@property.Name">@property.GetValue(context)</MudTd>}}@if (ChildSelectors.Any(selector => selector(context) != null && selector(context).Any())){<MudTd><MudLink @onclick="() => ToggleExpansion(context)">@(GetIsSelected(context) ? "v" : ">")</MudLink></MudTd>}  @code{[Parameter]public TItem context { get; set; } = default!;[Parameter]public List<Func<TItem, IEnumerable<object>>> ChildSelectors { get; set; } = new();[Parameter] public TItem Context { get; set; }[Parameter] public Dictionary<Func<TItem, IEnumerable<object>>, List<Func<object, IEnumerable<object>>>> ChildSelectorsForChild { get; set; }}

ParentComponent.razor

<MudTable T="TItem" Items="Items" Hover="true"><HeaderContent><MudCheckBox T="bool" Value="@selectAll" ValueChanged="ToggleSelectAll" id="chkAll"> </MudCheckBox>@foreach (var property in typeof(TItem).GetProperties()){if (property.GetCustomAttributes(typeof(DisplayAttribute), false).Length > 0){<MudTh>@property.Name</MudTh>}}</HeaderContent><RowTemplate>@ChildComponent(context)</RowTemplate>@* <ChildRowContent>@if (IsExpanded(context)){<MudTr><td colspan="@typeof(TItem).GetProperties().Count() + 1"><MudCard Elevation="0"><MudCardContent Class="pa-0"> @foreach (var childSelector in ChildSelectors) { if (childSelector(context) != null && childSelector(context).Any()) {<ParetnComponent TItem="childSelector(context).First().GetType()"         Items="childSelector(context)" ChildSelectors="ChildSelectorsForChild[childSelector]" IsExpanded="IsExpanded" ToggleExpansion="ToggleExpansion"></GeneralMultiSelectTable>   }}</MudCardContent></MudCard></td></MudTr>}   </ChildRowContent>*@</MudTable>@code{[Parameter] public IEnumerable<TItem> Items { get; set; }[Parameter] public Func<TItem, bool> IsExpanded { get; set; }[Parameter] public RenderFragment<TItem>  ChildComponent{ get; set; }}

Test.razor

<ParentComponent TItem="JunkFiles" Items="@junkFiles"    IsExpanded="IsExpanded"><ChildComponent ChildSelectors="@childSelectors"></ChildComponent></ParentComponent@code{public List<Func<JunkFiles, IEnumerable<object>>> childSelectors { get; } = new List<Func<JunkFiles, IEnumerable<object>>>{item => item.Items.Cast<object>()};public Dictionary<Func<JunkFiles, IEnumerable<object>>, List<Func<object, IEnumerable<object>>>> childSelectorsForChild = new Dictionary<Func<JunkFiles,IEnumerable<object>>, List<Func<object, IEnumerable<object>>>>{{ item => item.Items.Cast<object>(), new List<Func<object, IEnumerable<object>>>{item => ((FileNames)item).Items.Cast<object>()}}};}

But I am getting error unexpected attribute on ChildComponent when adding the value @childSelectors to Test.razor.How do I pass childSelectors defined in the Test.razor to ChildComponent.razor . I am trying to make ChildComponent a separate component . so that I can call then as recursive for related data .


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>