C
C#15mo ago
J.BE

❔ Bug in blazor?

Hello guys, i have encountered something strange in my blazor app. I'll try to explain it here. So i have to tables with below a row which shows the totals. These tables almost share the EXACT same code, the only way in they differ is the entities which are used to fill them. (both are records) As you can see in the image, only the second table shows the totals correctly by summing them up.
List<CategoryLine>? CategoryLines; // first table
List<Totals>? VatRateLines; //second table
List<CategoryLine>? CategoryLines; // first table
List<Totals>? VatRateLines; //second table
The user clicks a button, and this code gets executed, which fills the tables out.
private async Task FillCategories()
{
CategoryLines = null; // to trigger spinner
var result = await JflowerClient.TotalsPerCategoryAsync(DateOnly.FromDateTime(DateFilter.ToDateTime(TimeOnly.MinValue)));
CategoryLines = result;
}

private async Task FillBtwRates()
{
VatRateLines = null;
var result = await JflowerClient.TotalsPerBtwRateAsync(DateOnly.FromDateTime(DateFilter.ToDateTime(TimeOnly.MinValue)));
VatRateLines = result;
}
private async Task FillCategories()
{
CategoryLines = null; // to trigger spinner
var result = await JflowerClient.TotalsPerCategoryAsync(DateOnly.FromDateTime(DateFilter.ToDateTime(TimeOnly.MinValue)));
CategoryLines = result;
}

private async Task FillBtwRates()
{
VatRateLines = null;
var result = await JflowerClient.TotalsPerBtwRateAsync(DateOnly.FromDateTime(DateFilter.ToDateTime(TimeOnly.MinValue)));
VatRateLines = result;
}
7 Replies
J.BE
J.BE15mo ago
Both tables use the exact same component and child components
<Table Names="@(new[] { "Groep", "Totaal ex.", "Totaal btw", "Totaal incl." })"
MaxRows="@(CategoryLines?.Count ?? 0)">
@if (CategoryLines is not null)
{
@for (var i = 0; i < CategoryLines?.Count; i++)
{
var category = CategoryLines[i];
var index = i;
<Row>
<IntCell Selectable="false" Value="@(index + 1)"/>
<TextCell Value="@category.Name"/>
<DecimalCell Value="@category.TotExcl" Format="C"/>
<DecimalCell Value="@category.Vat" Format="C"/>
<DecimalCell Value="@category.TotIncl" Format="C"/>
</Row>
}
<TotalRow OfColumns="@(new[] { 2, 3, 4 })"/>
}
else { <Spinner/> }
</Table>
<Table Names="@(new[] { "BTW%", "Totaal ex.", "Totaal btw", "Totaal incl." })"
MaxRows="@(VatRateLines?.Count ?? 0)">
@if(VatRateLines is not null) {
@for (var i = 0; i < VatRateLines.Count; i++)
{
var vatRate = VatRateLines[i];
var index = i;
<Row>
<IntCell Selectable="false" Value="@((index + 1))"/>
<DecimalCell Value="@vatRate.Vat" Percentage="true"/>
<DecimalCell Value="@vatRate.TotExcl" Format="C"/>
<DecimalCell Value="@(vatRate.TotIncl-vatRate.TotExcl)"/>
<DecimalCell Value="@vatRate.TotIncl" Format="C"/>
</Row>
}
<TotalRow OfColumns="@(new[] { 2, 3, 4 })"/>
}
else { <Spinner/> }
</Table>
<Table Names="@(new[] { "Groep", "Totaal ex.", "Totaal btw", "Totaal incl." })"
MaxRows="@(CategoryLines?.Count ?? 0)">
@if (CategoryLines is not null)
{
@for (var i = 0; i < CategoryLines?.Count; i++)
{
var category = CategoryLines[i];
var index = i;
<Row>
<IntCell Selectable="false" Value="@(index + 1)"/>
<TextCell Value="@category.Name"/>
<DecimalCell Value="@category.TotExcl" Format="C"/>
<DecimalCell Value="@category.Vat" Format="C"/>
<DecimalCell Value="@category.TotIncl" Format="C"/>
</Row>
}
<TotalRow OfColumns="@(new[] { 2, 3, 4 })"/>
}
else { <Spinner/> }
</Table>
<Table Names="@(new[] { "BTW%", "Totaal ex.", "Totaal btw", "Totaal incl." })"
MaxRows="@(VatRateLines?.Count ?? 0)">
@if(VatRateLines is not null) {
@for (var i = 0; i < VatRateLines.Count; i++)
{
var vatRate = VatRateLines[i];
var index = i;
<Row>
<IntCell Selectable="false" Value="@((index + 1))"/>
<DecimalCell Value="@vatRate.Vat" Percentage="true"/>
<DecimalCell Value="@vatRate.TotExcl" Format="C"/>
<DecimalCell Value="@(vatRate.TotIncl-vatRate.TotExcl)"/>
<DecimalCell Value="@vatRate.TotIncl" Format="C"/>
</Row>
}
<TotalRow OfColumns="@(new[] { 2, 3, 4 })"/>
}
else { <Spinner/> }
</Table>
The total row shows and calculates the sums of columns 2, 3 and 4. As you can see it works perfectly for the second table but not the first table, and here comes the strangest thing, when i leave out the @if (CategoryLines is not null) check, and thus not show a spinner, it does show the totals for that table! Which is super strange because the second table does not require that! Anyone an idea why this might be?
JakenVeina
JakenVeina15mo ago
Both tables use the exact same component and child components
So, why are we not looking at the code that generates the data?
J.BE
J.BE15mo ago
because the data is correctly generated, thats why the tables are filled up, its the "totalrow" that gets the values from the specified columns, this is just calculated.
TotalRow:
public void Correct()
{
foreach (var index in OfColumns)
{
ColumnValues[index] = 0;
ColumnValues[index] = ParentComponent?
.Rows
.Sum(r => ((r as Row)?.Cells[index] as DecimalCell)?.Value ?? 0)
?? 0;
}
}
TotalRow:
public void Correct()
{
foreach (var index in OfColumns)
{
ColumnValues[index] = 0;
ColumnValues[index] = ParentComponent?
.Rows
.Sum(r => ((r as Row)?.Cells[index] as DecimalCell)?.Value ?? 0)
?? 0;
}
}
ParentComponent Table:
public void OnChildrenRendered()
{
foreach (var baseRow in Rows.FindAll(r => r is Row))
{
var row = (Row)baseRow;
if (RenderedRows.Contains(row)) continue;
Rows.Remove(row);
}
RenderedRows.Clear();
CorrectTotalRow();
StateHasChanged();
}

public void CorrectTotalRow()
{
((TotalRow?)Rows.Find(r => r is TotalRow))?.Correct();
}
ParentComponent Table:
public void OnChildrenRendered()
{
foreach (var baseRow in Rows.FindAll(r => r is Row))
{
var row = (Row)baseRow;
if (RenderedRows.Contains(row)) continue;
Rows.Remove(row);
}
RenderedRows.Clear();
CorrectTotalRow();
StateHasChanged();
}

public void CorrectTotalRow()
{
((TotalRow?)Rows.Find(r => r is TotalRow))?.Correct();
}
JakenVeina
JakenVeina15mo ago
alrighty so, what have you determined from debugging this?
J.BE
J.BE15mo ago
that blazor is trash
JakenVeina
JakenVeina15mo ago
Blazor Server or Blazor WASM?
Accord
Accord15mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts