dotnet / dotnet/aspnetcore

QuickGrid: Support sorting with a custom comparer.

Open
#45,478 2 comments 1 reaction 0 assignees View on GitHub
area-blazor enhancement feature-blazor-quickgrid
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

We would like to be able to sort with custom comparers, e.g., with a natural string comparer (*).

Which is possible with the current API, but it involves an item provider and custom handling of `sortBy` / `sortAscending`. See [here](https://github.com/kuba-si/AspLabs/tree/kuba/custom-comparer-existing-api-1). In the Blazor Server example, the pages that use an item provider (i.e.: "Provider" and "Virtualized") have a custom comparer which sorts country names by length rather than alphabetically:

![image](https://user-images.githubusercontent.com/102220637/205979257-fa275c35-9ca2-41f6-9686-1e7e149282f8.png)

This is too convoluted for our needs, though. We populate the grid from lightweight in-memory collections and don't use item providers.

(*) For clarity: we do have a natural string comparer implementation. The problem is that there is no easy way to plug it in.

### Describe the solution you'd like

We would like to have a simple API to specify a custom comparer for a single column. And we would like the grid itself to do the sorting. (Perhaps taking advantage of the `OrderBy` / `OrderByDescending` overloads which support custom comparers.)

See [here](https://github.com/kuba-si/AspLabs/tree/kuba/custom-comparer-new-api-1) for a working prototype for `TemplateColumn`.

And [here](https://github.com/kuba-si/AspLabs/tree/kuba/custom-comparer-new-api-2) for `PropertyColumn`.

In both cases the custom comparer (that sorts country names by length rather than alphabetically) works in the "In-memory" page:

![image](https://user-images.githubusercontent.com/102220637/205982681-fc482bef-2c9f-4029-8395-44489184d77d.png)

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the linked AspLabs prototypes for custom-comparer-new-api-1 and custom-comparer-new-api-2, covering TemplateColumn and PropertyColumn. Compare how each prototype configures the comparer and how the in-memory QuickGrid page sorts country names. Done means a simple per-column comparer API supports grid-owned ascending and descending sorting for both column types.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
frontend, web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.