I am using mud blazor and net core 8. I am calling an api to consult a report, so far so good, but now I need that reportis displayed when pressing a button and I feel like this changes everything because I don't know how to execute my server reload method from a button and pass it as my parameterTableState to configure pagination.....
When I load it at startup (without pressing any button) this works fine, but now I try to pass my function to the button and I can't find the right way to make it work the same.
My code:
My Backend component:
public partial class ProductsReport{ //property 1 //property 2 private MudTable<CustomItem> Table { get; set; } protected override void OnInitialized() { //init.... } private async Task<TableData<CustomItem>> ServerReload(TableState state, CancellationToken cancellationToken) { //get data from DB and configure pagination request var request = new CustomQuery(); request.pageNumber = state.Page + 1; request.pageSize = state.PageSize; var resp = await QueryProducts.GetAsync(request); var tableData = new TableData<RoleItem>(); if (resp) { //set Table component with pagination data from api tableData = new TableData<CustomItem> { TotalItems = resp.rows , Items = resp.Elements }; } else { //display errors } return tableData; }}My html razor:
<!--I need call ServerReload method from this button, bit not work becouse i need pass table state param to function backend--><MudButton Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" OnClick="ServerReload">Create my tenant</MudButton><!-- Before: <MudTable ServerData="@(new Func<TableState, CancellationToken, Task<TableData<CustomItem>>>(ServerReload))" @ref="Table">--><!--Now--><MudTable Elements="Table?.Items" @ref="Table" Striped="true" @ref="Table"><HeaderContent><MudTh><MudTableSortLabel SortLabel="Id" T="CustomItem">Identity</MudTableSortLabel></MudTh><MudTh><MudTableSortLabel SortLabel="Name" T="CustomItem">Name</MudTableSortLabel></MudTh><MudTh><MudTableSortLabel SortLabel="Price" T="CustomItem">Price</MudTableSortLabel></MudTh></HeaderContent><RowTemplate><MudTd DataLabel="Id">@context.Name</MudTd><MudTd DataLabel="Name">@context.IsStatic</MudTd><MudTd DataLabel="Price">@context.IsDefault</MudTd></RowTemplate><PagerContent><MudTablePager RowsPerPageString="rows per page" /></PagerContent></MudTable>In summary: I need to call my ServerReload method from a button and maintain my paging logic like this