Closed Nitin5acc closed 3 years ago
@code {
public HealthReportArgs HealthReportArgs { get; set; } = new HealthReportArgs() { };
public HealthReportRow[] HealthReportRows { get; set; } = new HealthReportRow[] { };
public async void HandleValidSubmit()
{
SpinnerService.Show();
var settings = new Settings(Configuration);
if (string.IsNullOrWhiteSpace(settings.HealthReportApiUrl))
{
throw new Exception($"Configuration value missing: {nameof(settings.HealthReportApiUrl)}");
}
this.HealthReportRows = await HttpClient.GetReportRows<HealthReportRow>(apiUrl: settings.HealthReportApiUrl, args: this.HealthReportArgs);
await JSRuntime.InvokeAsync<object>("TestDataTablesRemove", "#resultsTable");
this.StateHasChanged(); // ⬅
await JSRuntime.InvokeAsync<object>("InitDataTable", "#resultsTable");
SpinnerService.Hide();
}
}
@smallprogram Can you please tell me more about what do you think is wrong with the line? If I remove that How do I render after the button has been clicked
@smallprogram Can you please tell me more about what do you think is wrong with the line? If I remove that How do I render after the button has been clicked
First, call the component life cycle
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await JSRuntime.InvokeAsync<object>("InitDataTable", "#resultsTable");
}
}
Later, when the data set changes (increase, decrease, modify), first use JS to delete the table datatables instance, then change the data set, and then instantiate a new datatables instance.
public async Task HandleValidSubmit()
{
// Some animations, behavior determination, etc.
await JSRuntime.InvokeAsync<object>("TestDataTablesRemove", "#resultsTable");
// Data set changes
this.StateHasChanged();
await JSRuntime.InvokeAsync<object>("InitDataTable", "#resultsTable");
// Some animations, behavior determination, etc.
}
Is it really on-topic for "awesome-blazor" repository?
Is it really on-topic for "awesome-blazor" repository?
It has nothing to do with "awesome-blazor" repository, I just help him
@smallprogram When I try your suggestion the data table is not displayed at all when the data set has changed after button click. What might be wrong ? ( There is no exception though and it loads nicely first time)
Okay, I had to fix one line of Jquery to get this working- $('#resultsTable').DataTable().destroy();
am using jquery datatables on a blazor client app. In a razor component, I have a form that collects user inputs and gets data from the server. I then fill the HTML table with incoming data and invoke Jquery DataTable on it. It works fine as long as the number of rows are the same but I get below exception when the number of rows is reduced -
Below is my razor component -
And here are the scripts in index.html -