Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Problems with reactivness using blazor c#

$
0
0

Hi guys basically I have two individual components, I'm trying to send a list of reports from the first component to the second one for that I've created a global state so that i can share data among components, the issue is that I have a problem with the reactivness of my second component the list that I'm using is beeing updated but i have to force the renderization (adding something in the code of the second component like a comment for example) of my second component so that the table where I'm using the list shows a new record

This is the function that creates a new record in my first component

public partial class WellReportModal {     public void generateReport() {        string reportId = selectedWell.FieldName + selectedWell.LeaseName +        selectedWell.WellName + selectedWell.Completion + actionDate.ToString();        reportId = reportId.Replace("-", "")                   .Replace(" ", "")                   .Replace("/", "")                   .Replace(":", "")                   .Replace("p.m.", "")                   .Replace("a.m.", "");        GlobalStateProvider.WellReport newReport = new WellReport();        newReport.Actions = "Actions";        newReport.ReportId = reportId;        newReport.FieldName = selectedWell.FieldName;        newReport.LeaseName = selectedWell.LeaseName;        newReport.WellName = selectedWell.WellName;        newReport.Completion = selectedWell.Completion;        newReport.AnalysisDate = actionDate;        newReport.PayoutTime = economicTableList[5].Actual;        newReport.Recommendations = recommendations;        newReport.Status = wellStatus;        globalStateProvider.AddReport(newReport);    }}

In my global state i have something like this to updated the List

public partial class GlobalStateProvider{    public List<WellReport> WellReports { get; private set; } = new List<WellReport>();    public event Action? OnReportAdded;    public void AddReport(WellReport report)    {        WellReports.Add(report);        OnReportAdded?.Invoke();    }}

And in my second component I'm using the List for a Table

public partial class WellReports {    [CascadingParameter] public GlobalStateProvider globalStateProvider { get; set; }}<MudTable Items="@globalStateProvider.WellReports"><HeaderContent><MudTh>Actions</MudTh><MudTh>Report Date</MudTh><MudTh>Report Id</MudTh><MudTh>Urgency</MudTh><MudTh>Recommendations</MudTh><MudTh>Payout Time</MudTh></HeaderContent><RowTemplate><MudTd DataLabel="Actions">@context.Actions</MudTd><MudTd DataLabel="Report Date">@context.AnalysisDate</MudTd><MudTd DataLabel="Report Id">@context.ReportId</MudTd><MudTd DataLabel="Urgency">@context.Status.ToString()</MudTd><MudTd DataLabel="Recommendations">@context.Recommendations</MudTd><MudTd DataLabel="Payout Time">@context.PayoutTime</MudTd></RowTemplate></MudTable>

Does anyone know how to magane properly the reactiveness of blazor so that when a new record is created the second component recognizes the change in the List and updated the state of my component without forcing it?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>