Is it possible to set the default value of the Filter at the start, whenever I try I get an error of:
blazor.webassembly.js:1 crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.GridFilterColumn.OnInitializedAsync () <0x4a2e120 + 0x000e4> in <filename unknown>:0
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x3bfc598 + 0x0013a> in <filename unknown>:0
@page "/centrelist"
@layout DashLayout
@inject HttpClient httpClient
@inject IMatToaster matToaster
@attribute [Authorize(Policy = Policies.IsAdmin)]
<h3>Centre List</h3>
@if(records == null) {
<LoadingSpinner SpinnerOption="ELoadingSpinner.Circle" />
} else {
<SfGrid DataSource="@records" AllowPaging="true" AllowFiltering="true" AllowSorting="true" EnablePersistence="true">
<GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Menu">
<GridFilterColumn Field="@nameof(CentreListDto.Status)" MatchCase="false" Operator="Operator.Equal" Predicate="and" Value="@defaultFilter"></GridFilterColumn>
</GridFilterSettings>
<GridPageSettings PageSize="15"></GridPageSettings>
<GridColumns>
<GridColumn Field="@nameof(CentreListDto.Id)" HeaderText="Unique ID" IsPrimaryKey="true" Visible="false"></GridColumn>
<GridColumn Field="@nameof(CentreListDto.CentreNumber)" HeaderText="Centre Number" TextAlign="TextAlign.Right" Width="150" AllowFiltering="false"></GridColumn>
<GridColumn Field="@nameof(CentreListDto.Name)" HeaderText="Name" AllowFiltering="false" Width="300"></GridColumn>
<GridColumn Field="@nameof(CentreListDto.Telephone)" HeaderText="Phone Number" Width="200" AllowFiltering="false"></GridColumn>
<GridColumn Field="@nameof(CentreListDto.Status)" HeaderText="Status" FilterSettings="@(new FilterSettings { Type = Syncfusion.Blazor.Grids.FilterType.CheckBox})" Width="200">
</GridColumn>
<GridColumn Field="@nameof(CentreListDto.ActionAgainst)" HeaderText="Any Action" Width="1550" AllowFiltering="false">
<Template>
@{
var centre = (context as CentreListDto);
if (centre.ActionAgainst) {
<div class="centrestatusdiv e-inactivecolor">
<span class="centrestatustext e-inactivecolor">Action Taken Against</span>
</div>
} else {
<div class="centrestatusdiv e-activecolor">
<span class="centrestatustext e-activecolor">No Action Against</span>
</div>
}
}
</Template>
</GridColumn>
</GridColumns>
</SfGrid>
}
@code {
public List<CentreListDto> records { get; set; }
private long StatusId = 0;
public string defaultFilter = "Approved";
protected override async Task OnInitializedAsync() {
await GetCentreListByStatus();
}
private async Task GetCentreListByStatus() {
try {
var apiResponse = await httpClient.GetFromJsonAsync<ApiResponseDto<List<CentreListDto>>>($"{BaseURLs.GetCentreListByStatus}/{StatusId}");
if (apiResponse.IsSuccessStatusCode) {
records = apiResponse.Result;
} else {
matToaster.Add(apiResponse.Message + " : " + apiResponse.StatusCode, MatToastType.Danger, "Centre List Retrieval failed.");
}
} catch (Exception ex) {
matToaster.Add(ex.GetBaseException().Message, MatToastType.Danger, "Centre List Retrieval Error");
}
}
}