angular / angular/components

MatTableDataSource.sortingDataAccessor needs sortDirection

Open
#13,377 5 comments 0 reactions 0 assignees View on GitHub
area: material/table feature P4
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

#### Bug, feature request, or proposal:

Feature request

Enhance MatTableDataSource.sortingDataAccessor with sortDirection parameter to allow for better sort customization.

#### What is the expected behavior?

For example being able to define a sortingDataAccessor to *always* sort NULL values to the bottom (or top for that matter) regardless if 'asc' or 'desc'

#### What is the current behavior?

Null values are interpreted as 0 (zero) in case of numeric properties.

#### What are the steps to reproduce?

https://angular-8ubc1i.stackblitz.io

#### What is the use-case or motivation for changing an existing behavior?

I have a list of objects with various numeric properties, some of which are NULL.

I'd like to write a sortingDataAccessor to ALWAYS sort NULL values to the bottom regardless of 'asc' or 'desc' (since NULL is irrelevant/meaningless for our sort)
For this I seem to need a sortDirection in the sortingDataAccessor to either return min or max 'infinity' for NULL values.

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?

6.4.7

#### Is there anything else we should know?

Contributor guide

Open the contributing guide

Research direction

Locate MatTableDataSource and its sortingDataAccessor implementation, then reproduce the behavior in the linked StackBlitz example. Confirm the proposed accessor can use sort direction so NULL values remain consistently at the bottom or top for both ascending and descending sorts.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.