question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fix styling for non-sortable columns in sortable tables

See original GitHub issue

Summary

AFAICT the data table (even data table v2) doesn’t support tables where only some columns are sortable.

Justification

Our product needs to control which columns are and aren’t sortable. They don’t want to allow sorting on arbitrarily long text (note/description columns etc.) because it’s bad for performance and it’s just not useful.

Desired UX and success metrics

The.#{$prefix}--data-table--sort class currently goes on the table root node, and changes the padding on every <th> from 1rem to 0. It assumes that every <th> contains a <button> with 1rem padding.

But this breaks when only some of the columns are sortable, because the columns without sorting don’t have a <button> and therefore don’t have any padding… and alignment is off.

The quickest solution is adding CSS like

.#{$prefix}--data-table--sort th > .#{$prefix}--table-header-label {
	padding-left: $spacing-05;
	padding-right: $spacing-05;
}

However, maybe you should stop putting padding on the <th> altogether, and just always put it on the <th>'s child, regardless of if it’s a <button> or a plain .#{$prefix}--table-header-label. If _data-table-core.scss did that, then _data-table-sort.scss wouldn’t have to override the CSS set by _data-table-core.scss.

As a bonus, that would fix hidden issues when a sortable table contains a non-sortable table as one of its expando rows. Currently that nested table is getting caught by the parent table’s CSS, i.e. the CSS below (from _data-table-sort.scss) is inadvertently affecting nested tables.

.#{$prefix}--data-table--sort th, ... {
	padding: 0;
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wkeesecommented, Jun 12, 2020

Cool, thanks for fixing that. I filed #6261 to track the other (non-regression) issue.

1reaction
wkeesecommented, Jun 2, 2020

Things get worse when you change the row height (i.e. the size property). Here’s a screenshot from our app where only the first column is sortable.

Screen Shot 2020-06-02 at 9 39 53
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sortable Table Example | APG | WAI - W3C
Some sortable tables add an icon to unsorted columns to help users distinguish sortable columns from columns that cannot be sorted. It is ......
Read more >
Add column sorting to tables (#232664) · Issues - GitLab
I would like to propose an improvement to table column sorting ... I think potentially moving these styles to GitLab UI could go...
Read more >
Sorting behavior and headers styling · Issue #815 - GitHub
The last column in the example is not sortable to demo that it will not show the arrows on non-sortable columns. I have...
Read more >
Disable sorting of one column — DataTables forums
I am using dataTables 1.10 in server-side mode with Scroller. I tried to disable sorting in my first column by setting "orderable" to...
Read more >
Sortable Table Columns - Adrian Roselli
For longer tables, unless you use fixed table headers, it can be easy to lose track of which column is sorted once the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found