我想在MudSelect中使用MudTable:
<MudTable ServerData="@(new Func<TableState, Task<TableData<PlatformListResponseModel>>>(TableDataLoading))" Loading="isLoading" Hover="true" @ref="PlatformListTable">
<HeaderContent>
<MudTh><MudTableSortLabel SortLabel="platformName" T="PlatformListResponseModel">Platform Name</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortLabel="platformStatus" T="PlatformListResponseModel">Platform Status</MudTableSortLabel></MudTh>
<MudTh></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd>@context.platformName (@context.platformID)</MudTd>
<MudTd>
<MudSelect T="int" Value="context.platformStatus" ValueChanged="@((int selectedValue) => HandlePlatformStatus(selectedValue, context.platformStatus))">
<MudSelectItem Value="0">Open</MudSelectItem>
<MudSelectItem Value="1">Close</MudSelectItem>
<MudSelectItem Value="2">Maintain</MudSelectItem>
</MudSelect>
</MudTd>
<MudTd>
<MudButton>More</MudButton>
</MudTd>
</RowTemplate>
<NoRecordsContent>
<MudText>No Data!</MudText>
</NoRecordsContent>
<PagerContent>
<MudTablePager />
</PagerContent>
</MudTable>
更改select时,我将调用API,因此我使用ValueChanged调用事件函数。如果在MudSelect中设置值,则在更改select项时,它不会在显示时发生更改。如果我更改成功,我想检查api服务响应。
我想知道,如何将MudSelect设置为在MudTable中获取原始值,以及如何在显示中进行更改?如果改变成功,块将显示新的,如果更改失败,则显示原块。
是否有任何方法可以更改select显示而不重新加载表数据?
发布于 2022-10-21 16:51:50
试试这个:
...
<MudTd>
<MudSelect T="int" Value="context.platformStatus" ValueChanged="@((int selectedValue) => HandlePlatformStatus(selectedValue, context))">
<MudSelectItem Value="0">Open</MudSelectItem>
<MudSelectItem Value="1">Close</MudSelectItem>
<MudSelectItem Value="2">Maintain</MudSelectItem>
</MudSelect>
</MudTd>
...
@code {
private async Task HandlePlatformStatus(int selectedValue, PlatformListResponseModel context)
{
// call api and get result
if (result.IsSuccess)
{
context.platformStatus = selectedValue;
}
}
}
https://stackoverflow.com/questions/74105056
复制相似问题