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

Enable multi-selection on both the child rows and the main MudTable when the parent MudTable is selected (MultiSelection='true')

$
0
0

I am using mudtable to list the related data , I need to select the childrowcontent too when theMultiSelection="true" . How do I do this. I found the related data example in https://mudblazor.com/components/table#table-with-related-data.

I have added my code here. If this is not possible what is the alternative. I am very new to programming and MudBlazor. I have Like Grandparents->parents->Grandchildren relationship.When the multirow selection is turned ON I need to select All records of Grandparents and Parents.When the Grandparent is clicked it will show the Parents and when the parents are clicked it will show Grandchildren.I need Both the Grandparent's and Parents check box selected when the Multirow is selected.

<MudTable @ref="_mudtable" T="JunkFiles" Items="@junkFiles" MultiSelection="true" Hover="true"          @bind-SelectOnRowClick="@_selectOnRowClick"><HeaderContent><MudTh>Name</MudTh><MudTh>Sign</MudTh></HeaderContent><RowTemplate><MudTd DataLabel="Name">@context.Name</MudTd><MudTd DataLabel="Sign">@context.Size</MudTd>        @if (@context.FileNames.Count > 0)        {<MudTd><MudLink @onclick="() => ToggleExpansion(context)">@(context.IsExpanded ? "v" : ">")</MudLink></MudTd>        }</RowTemplate><ChildRowContent>        @if (context.IsExpanded)        {<MudTr><td colspan="4"><MudCard Elevation="0"><MudCardContent Class="pa-0"><MudTable Items="@context.FileNames" MultiSelection="true" Context="FileNameContext" Hover="true" Breakpoint="Breakpoint.Sm" Elevation="0"><RowTemplate><MudTd DataLabel="File Name">@FileNameContext.FileName</MudTd><MudTd>                                        @if (@FileNameContext.SubFileNames.Count > 0)                                        {<MudLink @onclick="() => ToggleSubExpansion(FileNameContext)">@(FileNameContext.IsExpanded ? "v" : ">")</MudLink>                                        }</MudTd></RowTemplate><ChildRowContent>                                    @if (FileNameContext.IsExpanded)                                    {<MudTr><td colspan="4"><MudCard Elevation="0"><MudTable Height="150px" Items="@FileNameContext.SubFileNames" Context="SubFileNameContext" Hover="true" Breakpoint="Breakpoint.Sm" Elevation="0"><RowTemplate><MudTd DataLabel="SubFileName ">@SubFileNameContext.SubFileName</MudTd></RowTemplate></MudTable></MudCard></td></MudTr>                                    }</ChildRowContent></MudTable></MudCardContent></MudCard></td></MudTr>        }</ChildRowContent></MudTable>public class JunkFiles {    public string Name { get; set; } = string.Empty;    public string Size { get; set; } = string.Empty;    public List<FileNames> FileNames { get; set; } = new();    public bool IsExpanded { get; set; } = false;    public JunkFiles(string name, string size , List<FileNames> filename)    {        Name = name;        Size = size;        FileNames = filename;    }}public class FileNames{    public string FileName { get; set; } = string.Empty;    public List<SubFileNames> SubFileNames { get; set; } = new();    public bool IsExpanded { get; set; } = false;    public  FileNames (String fileName , List<SubFileNames> subFileName )     {        FileName = fileName;        SubFileNames = subFileName;    }}public class SubFileNames{    public string SubFileName { get; set; } = string.Empty;    public SubFileNames (string subFileName)    {        SubFileName = subFileName;    }} protected override void OnInitialized() {     junkFiles = new List<JunkFiles>     {            new JunkFiles("Temporary files","1.07GB",             new List<FileNames>             {                 new FileNames(@"c:\windows\temp\*",                 new List<SubFileNames>                 {                     new SubFileNames(@"c:\windows\temp\file.log"),                     new SubFileNames(@"c:\windows\temp\file.xml"),                     new SubFileNames(@"c:\windows\temp\file.tmp")                 }),                 new FileNames(@"C:\Users\user\AppData\Local\Temp\*",                 new List<SubFileNames>                 {                    new SubFileNames(@"c:\windows\temp\file1.log"),                     new SubFileNames(@"c:\windows\temp\file2.xml"),                     new SubFileNames(@"c:\windows\temp\file3.tmp")                 })             }),            new JunkFiles("Empty Recycle Bin","6.39MB",            new List<FileNames>             {                 new FileNames(@"c:\tfs\temp\file1.cs",new (){}),                                        new FileNames(@"c:\tfs\temp\file2.cs",new (){}),                                        new FileNames(@"c:\tfs\temp\file3.cs",new (){}),             }),            new JunkFiles("Memory Dump Files","63.24MB",            new List<FileNames>             {                 new FileNames(@"c:\users\user1\AppData\Local\CrashDumps\*.dmp", new List<SubFileNames>                 {                     new SubFileNames(@"c:\users\user1\AppData\Local\CrashDumps\file1.dmp"),                     new SubFileNames(@"c:\users\user1\AppData\Local\CrashDumps\file2.dmp"),                     new SubFileNames(@"c:\users\user1\AppData\Local\CrashDumps\file3.dmp"),                 })             }),            new JunkFiles("Test Files","63.24MB", new List<FileNames>())     };     var s = junkFiles; }private void ToggleExpansion(JunkFiles junkFile){    junkFile.IsExpanded = !junkFile.IsExpanded;}private void ToggleSubExpansion(FileNames fileName){    fileName.IsExpanded = !fileName.IsExpanded;}

I added MultiSelection="true" on both the table It works on Individual tables , but I want the Multiselection on the Main mudtable enable it on both GrandParent and Parent Mudtable.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



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