Completed
Last Updated: 09 Jan 2023 09:29 by ADMIN
Release 4.0.0 (18 Jan 2023) (R1 2023)
Joeri
Created on: 01 Feb 2021 09:20
Category: Grid
Type: Feature Request
24
Sorted CheckboxListFilter by default

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.

---

7 comments
ADMIN
Marin Bratanov
Posted on: 11 May 2022 18:59

Thanks for sharing, David, that's exactly how I would approach this too.

 

--Marin

David Rhodes
Posted on: 11 May 2022 08:02
Sorry, below the component is called TelerikGridFilter.razor
David Rhodes
Posted on: 11 May 2022 08:00

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");
            if (prospects != null && prospects.Any())
            {
                professions = prospects.Select(x => x.Profession).OrderBy(x => x).Distinct().ToList()!;
                applicationTypes = prospects.Select(x => x.ApplicationType).OrderBy(x => x).Distinct().ToList()!;
            }

 

And add the Filter to the Column

 

            <GridColumn Field="@(nameof(ProspectSummaryViewModel.Profession))" Width="100px" Groupable="false">
                <FilterMenuTemplate>
                    <TelerikGridFilter Context="@context" Field="@(nameof(ProspectSummaryViewModel.Profession))" Data="@professions" />
                </FilterMenuTemplate>
            </GridColumn>
            <GridColumn Field="@(nameof(ProspectSummaryViewModel.ApplicationType))" Width="120px" Groupable="false">
                <FilterMenuTemplate>
                    <TelerikGridFilter Context="@context" Field="@(nameof(ProspectSummaryViewModel.ApplicationType))" Data="@applicationTypes" />
                </FilterMenuTemplate>
            </GridColumn>
Jon
Posted on: 26 Jul 2021 16:51

FilterSortOrder.Ascending

FilterSortOrder.Descending

FilterSortOrder.None

perhaps?

ADMIN
Marin Bratanov
Posted on: 15 Feb 2021 12:52

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/.

Philip
Posted on: 15 Feb 2021 03:55

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

 

ADMIN
Marin Bratanov
Posted on: 01 Feb 2021 11:55

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/.