MudTable table state is empty after publishing when using ServerData
brycehewett opened this issue · comments
Bug type
Component
Component name
MudTable
What happened?
When using the ServerData parameter on MudTable locally the table works as it should, however after publishing the app the table state is empty and results in no data being returned from the API.
Expected behavior
When the app is published the state of MudTable should be returned in the ServerData function, so that the state of the table can be used to paginate and sort data.
Reproduction link
https://github.com/brycehewett/mudblazor-tablebug
Reproduction steps
- Setup the MudTable using the ServerData parameter:
<MudTable T="WeatherForecast"
ServerData="@(new Func<TableState, Task<TableData<WeatherForecast>>>(ServerReload))"
Hover="true"
SortLabel="Sort By"
Elevation="0">
<HeaderContent>
<MudTh><MudTableSortLabel SortLabel="date" T="WeatherForecast">Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortLabel="tempc" T="WeatherForecast">Temp. (C)</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortLabel="tempf" T="WeatherForecast">Temp. (F)</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortLabel="summary" T="WeatherForecast">Summary</MudTableSortLabel></MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Date">@context.Date</MudTd>
<MudTd DataLabel="Temp. (C)">@context.TemperatureC</MudTd>
<MudTd DataLabel="Temp. (F)">@context.TemperatureF</MudTd>
<MudTd DataLabel="Summary">@context.Summary</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
</MudTable>
@code {
private async Task<TableData<WeatherForecast>> ServerReload(TableState state)
{
var res = await Http.PostAsJsonAsync<TableState>("WeatherForecast", state);
return await res.Content.ReadFromJsonAsync<TableData<WeatherForecast>>();
}
}
- Setup the api to return the related data:
[HttpPost]
public IActionResult GetForecasts(TableState state)
{
var rng = new Random();
var data = Enumerable.Range(1, 25).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
});
switch (state.SortLabel)
{
case "tempc":
data = data.OrderByDirection(state.SortDirection, o => o.TemperatureC);
break;
case "tempf":
data = data.OrderByDirection(state.SortDirection, o => o.TemperatureF);
break;
case "summary":
data = data.OrderByDirection(state.SortDirection, o => o.Summary);
break;
default:
data = data.OrderByDirection(state.SortDirection, o => o.Date);
break;
}
return Ok(new TableData<WeatherForecast>() {
TotalItems = data.Count(),
Items = data.Skip(state.Page * state.PageSize).Take(state.PageSize)
});
}
- Publish the application
- Load table and try sorting or using the table pager
Relevant log output
No response
Version (bug)
6.0.11
Version (working)
6.0.10
What browsers are you seeing the problem on?
Firefox, Chrome
On what operating system are you experiencing the issue?
Windows, Mac OSX
Pull Request
- I would like to do a Pull Request
Code of Conduct
- I agree to follow this project's Code of Conduct
After looking into this some more, I've narrowed this down to a change between 6.0.10 and 6.0.11. Also I'm able to work around this issue by setting PublishTrimmed to false, which makes me think this is related to the trimming changes in 6.0.11, however I have no idea how to fix it.
I was able to work around this by adding a trimmer config to my project. If anyone else runs into this issue, this solution worked for me.
- Add the following to the client project
<ItemGroup><TrimmerRootDescriptor Include="TrimmerConfig.xml" /></ItemGroup>
- Add the following to TrimmerConfig.xml in the client project root directory
<linker><assembly fullname="MudBlazor"><type fullname="MudBlazor.TableState"></type></assembly></linker>