gregnb / gregnb/mui-datatables

How to sort empty values at the end the table? (via customSort?)

Open
#1,336 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.7k
Forks
906
PR merge metrics
No merged PRs in 30d

Description

Hello,

We're using MUIDataTable for a while now, because that's the best table-oriented component the previous front developer had chosen.
Now he's not here, we have to try our best to make it meet our users' expectation.

That's why I'm opening a few issues regarding various aspects of customization of MUIDataTable.
For this purpose, I've forked your Codesandbox and created a little showcase of all our issues:
https://codesandbox.io/s/muidatatables-misc-requests-4vkxk

Some columns can have no data (either empty string or null), and nothing get display: it's OK for us.

We have set a default (ascendant) sort on the "New Role" column.
In our example, the first 2 rows with "New Role" = empty appear at the top of the table.
We want them to appear at the end of the table (i.e. on page 2), the same way it's possible in SQL (at least on Oracle) to ask for `NULLS LAST`.

I suppose this is not feasible "by default", so probably will require implementing a `customSort`.
But how can we implement such a function without implementing a full default sorting function from scratch? I mean, would it be possible to simply re-use the default MUIDataTable sort function?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by inspecting the linked CodeSandbox and the MUIDataTable customSort option, then trace how the default sort behavior is exposed. The work is done when empty strings and null values sort to the end in ascending order without requiring a wholly separate sorting implementation, while the existing ordering behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.