I've written a generic grid component where I've a checkbox in column header which can be selected to check all rows checkboxes and it working fine but there is an issue when I'm unselecting any other checkboxes then the main checkbox should also be unselected and that is not working as expected:
below is my code for the generic grid-
@if (Items == null)
{
<p><em>Loading...</em></p>
}
else {
<table class="table">
<thead>
<tr>
<th>
<input type="checkbox" id="chkAll" checked="@SelectMain" @onchange="ChangeCheckboxState"/>
</th>
@Columns(default(TItem))
</tr>
</thead>
<tbody>
@foreach (var item in Items) {
var id = $"chk{counter}";
<CascadingValue Value="item">
<tr>
<td class="col-checkbox chkColumn quarter">
<input type="checkbox" id="@id" checked="@SelectAll" @onchange="ChangeCheckboxSingle"/>
</td>
@Columns(item)
</tr>
</CascadingValue>
counter++;
}
</tbody>
</table>
}
@code {
[Parameter]
public IList<TItem> Items { get; set; }
[Parameter]
public RenderFragment<TItem>? Columns { get; set; }
public bool SelectAll { get; set; } = false;
public bool SelectMain { get; set; } = false;
int counter = 1;
void ChangeCheckboxState(ChangeEventArgs e){
if (Convert.ToBoolean(e.Value))
SelectAll = true;
else
SelectAll = false;
}
void ChangeCheckboxSingle(ChangeEventArgs e){
SelectMain = false;
StateHasChanged();
}
}
and lastly, what is the actual difference between @onselectionchange and @onchange.
