[英]Is there any way to toggle hiding/showing a table column in MudBlazor's MudTable
I have a simple MudBlazor MudTable, but looking through the MudBlazor documentation, and after some Googling, I didn't see anything about being able to show/hide columns for a MudTable or if it's even possible.我有一个简单的 MudBlazor MudTable,但查看 MudBlazor 文档,并在谷歌搜索后,我没有看到任何关于能够显示/隐藏 MudTable 的列的信息,甚至没有看到任何可能。 Does anyone know a way?有人知道办法吗?
Here is an example of the table I am using:这是我正在使用的表格的示例:
@using System.Net.Http.Json
@using MudBlazor.Examples.Data.Models
@inject HttpClient httpClient
<MudTable Items="@Elements.Take(4)" Hover="true" Breakpoint="Breakpoint.Sm" Loading="@_loading" LoadingProgressColor="Color.Info">
<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" HideSmall="_hidePosition">@context.Position</MudTd>
<MudTd DataLabel="Molar mass">@context.Molar</MudTd>
</RowTemplate>
</MudTable>
<MudSwitch @bind-Checked="_hidePosition">Hide <b>position</b> when Breakpoint=Xs</MudSwitch>
<MudSwitch @bind-Checked="_loading">Show Loading</MudSwitch>
@code {
private bool _hidePosition;
private bool _loading;
private IEnumerable<Element> Elements = new List<Element>();
protected override async Task OnInitializedAsync()
{
Elements = await httpClient.GetFromJsonAsync<List<Element>>("webapi/periodictable");
}
}
I have tried searching for any possible solution and haven't been able to find anything.我曾尝试寻找任何可能的解决方案,但一无所获。
try.mudblazor.com/snippet/QYQwvwbppieauJwP There you have it, but as @Vischi said, the vertical screen size must be large enough. try.mudblazor.com/snippet/QYQwvwbppieauJwP你有它,但正如@Vischi 所说,垂直屏幕尺寸必须足够大。 Try dragging the divider to the left to see the table as in examples.尝试将分隔线向左拖动以查看示例中的表格。
@using System.Net.Http.Json
@using MudBlazor.Examples.Data.Models
@inject HttpClient httpClient
<MudTable Items="@Elements.Take(4)" Hover="true" Breakpoint="Breakpoint.Sm" Loading="@_loading" LoadingProgressColor="Color.Info">
<HeaderContent>
<MudTh>Nr</MudTh>
<MudTh>Sign</MudTh>
<MudTh>Name</MudTh>
@if(!_hidePosition)
{
<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>
@if(!_hidePosition)
{
<MudTd DataLabel="Position" HideSmall="_hidePosition">@context.Position</MudTd>
}
<MudTd DataLabel="Molar mass">@context.Molar</MudTd>
</RowTemplate>
</MudTable>
<MudSwitch @bind-Checked="_hidePosition">Hide <b>position</b> when Breakpoint=Xs</MudSwitch>
<MudSwitch @bind-Checked="_loading">Show Loading</MudSwitch>
@code {
private bool _hidePosition;
private bool _loading;
private IEnumerable<Element> Elements = new List<Element>(){new Element(), new Element(), new Element()};
protected override async Task OnInitializedAsync()
{
//Elements = await httpClient.GetFromJsonAsync<List<Element>>("webapi/periodictable");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.