英文:
Why SelectOnRowClick doesn't disable toggling the checkbox state on row-click?
问题
对不起,我只能提供有关代码的帮助。
英文:
I'm using MudBlazor v.6.1.5 and trying to create table with "row selection on click" property blocked the same way as in MudBlazor docs (https://mudblazor.com/components/table#multi-selection)
For some reason propety "SelectOnRowClick" doesn't disable toggling the checkbox state for tables in my project. Here is simple code snippet:
@page "/test"
<MudSwitch @bind-Checked="@_selectOnRowClick">SelectOnRowClick: @_selectOnRowClick</MudSwitch>
<MudText Inline="true">Item: @_selectedItemText</MudText>
<MudText>Selected items (@selectedItems?.Count): @(selectedItems == null ? "" : string.Join(", ", selectedItems.OrderBy(x => x.Sign).Select(x => x.Sign)))</MudText>
<MudTable @ref="_table" T="Element" Items="@Elements" MultiSelection="true" @bind-SelectedItems="selectedItems" Hover="true"
OnRowClick="@OnRowClick" @bind-SelectOnRowClick="@_selectOnRowClick">
<HeaderContent>
<MudTh>Nr</MudTh>
<MudTh>Sign</MudTh>
<MudTh>Name</MudTh>
<MudTh>Position</MudTh>
<MudTh>Molar mass</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Nr">@context.Number</MudTd>
<MudTd DataLabel="Sign">@context.Sign</MudTd>
<MudTd DataLabel="Name">@context.Name</MudTd>
<MudTd DataLabel="Position">@context.Position</MudTd>
<MudTd DataLabel="Molar mass">@context.Molar</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
<FooterContent>
<MudTd colspan="5">Select All</MudTd>
</FooterContent>
</MudTable>
@code {
private HashSet<Element> selectedItems = new HashSet<Element>();
private IEnumerable<Element> Elements = new List<Element>();
private bool _selectOnRowClick = true;
private MudTable<Element> _table;
private string _selectedItemText = "No row clicked";
protected override async Task OnInitializedAsync()
{
Elements = new List<Element>()
{
new Element(){Name="Hydrogen", Sign="H", Position=0, Molar = 1.00794},
new Element(){Name="Hydrogen", Sign="H", Position=0, Molar = 1.00794},
new Element(){Name="Hydrogen", Sign="H", Position=0, Molar = 1.00794},
new Element(){Name="Hydrogen", Sign="H", Position=0, Molar = 1.00794},
new Element(){Name="Hydrogen", Sign="H", Position=0, Molar = 1.00794},
new Element(){Name="Hydrogen", Sign="H", Position=0, Molar = 1.00794}
};
}
void OnRowClick(TableRowClickEventArgs<Element> args)
{
_selectedItemText = $"{args.Item.Name} ({args.Item.Sign})";
}
public class Element
{
public string Group { get; set; }
public int Position { get; set; }
public string Name { get; set; }
public int Number { get; set; }
public string Sign { get; set; }
public double Molar { get; set; }
public IList<int> Electrons { get; set; }
public override string ToString()
{
return $"{Sign} - {Name}";
}
}
}
The same code in MudBlazor playground works fine, am I missing something?
答案1
得分: 1
问题已通过将MudBlazor更新到v6.1.9解决。
英文:
The problem was solved by updating MudBlazor to v6.1.9.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论