Hello,
First of all: thank you for implementing the Excel like filtering with the new CheckBox Filter! This was a feature that was highly sought after in our development team.
But there is one thing I am missing: the checkbox list has no option for sorting.
If we want to sort our filters now we have to implement the FilterMenuTemplate in every column that has filtering active (which are a lot) and define the list with filter options and filter it ourselves.
Is this something that can be fixed easily?
---
ADMIN EDIT
We will probably sort ascending the values by default (out-of-the0box), and any other custom sorts should be implemented through the filter menu template.
---
Thanks for sharing, David, that's exactly how I would approach this too.
--Marin
Here's how I've implemented it if it helps anyone whilst waiting, this is just for List<string>:
I created a new component to handle the filter
<div class="filter-values-container">
@if (Data != null)
{
foreach (var item in Data)
{
<div class="mb-1">
@{
string label = string.IsNullOrEmpty(item) ? "Not set" : item;
}
<TelerikCheckBox Value="@(GetFilterValues(Context.FilterDescriptor).Contains(item))"
Id="@($"name_{label}")"
ValueChanged="@((bool value) => ColumnValueChanged(value, item, Field, Context.FilterDescriptor))">
</TelerikCheckBox>
<label for="@($"name_{label}")" class="ms-1">@label</label>
</div>
}
}
</div>
@code {
[Parameter] public string Field { get; set; } = null!;
[Parameter] public List<string>? Data { get; set; }
[Parameter] public FilterMenuTemplateContext Context { get; set; } = null!;
/// <summary>
/// Telerik Grid filtering
/// </summary>
/// <param name="filterDescriptor"></param>
/// <returns></returns>
private static List<string> GetFilterValues(CompositeFilterDescriptor filterDescriptor)
{
return filterDescriptor.FilterDescriptors.Select(f => (f as FilterDescriptor)!.Value?.ToString()).ToList()!;
}
/// <summary>
/// Telerik Grid filtering
/// </summary>
/// <param name="value"></param>
/// <param name="itemValue"></param>
/// <param name="columnName"></param>
/// <param name="filterDescriptor"></param>
private static void ColumnValueChanged(bool value, string itemValue, string columnName, CompositeFilterDescriptor filterDescriptor)
{
var filter = filterDescriptor.FilterDescriptors.FirstOrDefault(f => (f as FilterDescriptor)!.Value?.ToString() == itemValue);
filterDescriptor.LogicalOperator = FilterCompositionLogicalOperator.Or;
if (value && filter == null)
{
filterDescriptor.FilterDescriptors.Add(new FilterDescriptor(columnName, FilterOperator.IsEqualTo, itemValue));
}
else if (!value && filter != null)
{
filterDescriptor.FilterDescriptors.Remove(filter);
}
}
}
Get the data needed for the filters
prospects = await Http.GetFromJsonAsync<List<ProspectSummaryViewModel>>("Prospect/AllProspects");
And add the Filter to the Column
<GridColumn Field="@(nameof(ProspectSummaryViewModel.Profession))" Width="100px" Groupable="false">
FilterSortOrder.Ascending
FilterSortOrder.Descending
FilterSortOrder.None
perhaps?
Hello Philip,
At the moment, our intention is to add default ascending sorting for the value without extra parameters and settings as this would be the typical case. For custom sorts and orders, a custom filter menu can be created through the filter menu template. I've updated my edit on the opener post to make it more eye-catching because it already had that information, but it seems it is not visible enough.
To know when this happens, make sure you've clicked the Follow button on the left hand side, at the top.
Regards,
Marin Bratanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
Bump to this! :)
Yes - having it sort ascending would emulate "Excel-like" filtering behavour.
Also, imagine a very long list, then the check-box column becomes non-functional as you will need to use the search.
See small example attached where the user wants to look down a list to find inventory items only within "OEG" crates.
Or a list of documents that have a sequential number;
Or imagine a list of names of people and you want to find if someone exists - noting that sometimes, filters are used by the user as a check to see if a value exists before drilling down.
Regards
Phil
Hello Joeri,
If you create collections of the same model the grid uses, you could make a generic component that provides that list as desired, with smaller overhead (less code repetition) - you could pass the field name from the parent to it together with the context.
The grid merely takes the distinct values and does not apply any sorting to them. If you want that to change, how would you expect it to be exposed for configuration? Or, would you expect that to happen automatically in, say, ascending order, and if someone wants a natural sort or other sort - they should implement templates?
Regards,
Marin Bratanov
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.