Items 1, 2b, and 3 are shown in the gif below.
Item 1 is specifically using DropDownDataGrid in a DataGrid FilterTemplate
- Unchecking the last checked item generates a DataGrid SQL Where of "0 = 1" and returns zero rows. After that, the only way to return all rows again is to check another item, then click the "X" to Clear them all.
Is there any way to reset the filter upon unchecking the last item so it instead defaults back to show all like on load? - a. Attempting to reset the filter by setting the @bind-Value property to new List<string>():
This has the same behavior as item 1 and returns zero rows
b. Attempting to reset the filter by setting the @bind-Value property to null:
This does reset the filter (temporarily), but it leaves the Label and the Search box with text still. Is there anyway to clear the Label and Search box programmatically? I've been able to workaround this by clearing the Label with jQuery, but am unable to clear the Search box. - Also related to setting the @bind-Value property to null, even though it did temporarily reset the filter, after clicking another Item it will re-check the original item as well.
<h1>DataGrid <strong>LoadData</strong></h1>
<p>The <code>LoadData</code> event allows you to perform custom paging, sorting and filtering.</p>
<div class="row">
<div class="col-md-8">
<RadzenButton Text="Reset" Click="@Reset" Style="margin-bottom: 20px;" />
<RadzenDataGrid style="height: 335px" @ref="grid" IsLoading=@isLoading Count="@count" Data="@staff" LoadData="@LoadData" FilterMode="FilterMode.Advanced"
AllowSorting="true" AllowFiltering="true" AllowPaging="true" PageSize="10" PagerHorizontalAlign="HorizontalAlign.Justify"
PagerPosition="PagerPosition.Top" TItem="StaffSearchView" ColumnWidth="200px" ShowPagingSummary="true">
<Columns>
<RadzenDataGridColumn TItem="StaffSearchView" Property="StaffNumber" Filterable="false" Title="ID" Frozen="true" Width="70px" TextAlign="TextAlign.Center" />
<RadzenDataGridColumn TItem="StaffSearchView" Property="GroupName" Title="Group"
Type="typeof(IEnumerable<string>)" FilterValue="@selectedGroups" FilterOperator="FilterOperator.Contains" Width="200px">
<FilterTemplate>
<RadzenDropDownDataGrid @ref="gridGroups" AllowRowSelectOnRowClick="false" AllowFiltering="true" PageSize="10"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" AllowClear="true" @bind-Value=@selectedGroups
Multiple="true" Placeholder="Select..." Data=@groups TextProperty="GroupName" ValueProperty="GroupName"
Style="width: 300px">
<Columns>
<RadzenDropDownDataGridColumn Width="40px" Sortable="false">
<Template Context="groupData">
<RadzenCheckBox TriState="false" Value="@(selectedGroups != null && selectedGroups.Contains(((GroupSetting) groupData).GroupName))"
TValue="bool" Change=@(args => { gridGroups.SelectItem(groupData); }) />
</Template>
</RadzenDropDownDataGridColumn>
<RadzenDropDownDataGridColumn Property="GroupName" Title="Group" Width="200px" />
</Columns>
</RadzenDropDownDataGrid>
</FilterTemplate>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="StaffSearchView" Property="AccessLevel" Filterable="false" Title="Active" Width="70px" TextAlign="TextAlign.Center" />
</Columns>
</RadzenDataGrid>
</div>
</div>
@code {
RadzenDataGrid<StaffSearchView> grid;
int count;
IEnumerable<StaffSearchView> staff;
bool isLoading = false;
IEnumerable<string> selectedGroups;
private RadzenDropDownDataGrid<IEnumerable<string>> gridGroups;
IEnumerable<GroupSetting> groups;
protected override async Task OnInitializedAsync()
{
groups = await GroupSettingRepository.GetAllAsync(s => s.GroupStatus == true, s => s.OrderBy(x => x.GroupName));
}
void OnSelectedTitlesChange(object value)
{
if (selectedGroups != null && !selectedGroups.Any())
{
selectedGroups = null;
}
}
async Task Reset()
{
selectedGroups = null;
grid.Reset(true);
await grid.FirstPage(true);
}
async Task LoadData(LoadDataArgs args)
{
isLoading = true;
await Task.Yield();
var query = StaffRepository.GetStaffSearchQuery(orderBy: s => s.OrderBy(x => x.LastName));
if (!string.IsNullOrEmpty(args.Filter))
{
query = query.Where(args.Filter);
}
if (!string.IsNullOrEmpty(args.OrderBy))
{
query = query.OrderBy(args.OrderBy);
}
count = query.Count();
staff = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList();
isLoading = false;
}
}