SelectOnRowClick为什么不会禁用在单击行时切换复选框状态?

huangapple go评论52阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月16日 19:15:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471464.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定