Skip to content

Change replacement to add a class in TableSort.svelte#2

Open
ploshadka wants to merge 1 commit intomattiash:masterfrom
ploshadka:master
Open

Change replacement to add a class in TableSort.svelte#2
ploshadka wants to merge 1 commit intomattiash:masterfrom
ploshadka:master

Conversation

@ploshadka
Copy link

It was impossible to put classes on the th header. They were removed and replaced by another class. Because of this, the styles of the header didn't work.

It was impossible to put classes on the th header. They were removed and replaced by another class. Because of this, the styles of the header didn't work.
@Michael-Ashfield
Copy link

This seems to apply both an ascending and descending class at the same time if any of the headers are toggled to both.

: CLASSNAME_ASC)
: CLASSNAME_ASC

th.classList.add('CLASSNAME_SORTABLE')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be "th.classList.add(CLASSNAME_SORTABLE)" as this is currently adding a string instead of the "sortable" class

@Michael-Ashfield
Copy link

This also appears to leave the "ascending" or "descending" class on columns which are no longer being sorted.

for (let i = 0; i < th.length; i++) {
if (th[i].dataset.sort) {
th[i].className = CLASSNAME_SORTABLE
th[i].classList.add(CLASSNAME_SORTABLE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the below to clear any leftover "ascending" or "descending" classes where there are no longer being sorted.

if (th[i].classList.contains(CLASSNAME_ASC)) {
          th[i].classList.remove(CLASSNAME_ASC);
        } else if (th[i].classList.contains(CLASSNAME_DESC)) {
          th[i].classList.remove(CLASSNAME_DESC);
        }

? CLASSNAME_DESC
: CLASSNAME_ASC)
: CLASSNAME_ASC

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the below to ensure only "ascending" or "descending" is shown, not both:

th.classList.remove(
   descAsc == CLASSNAME_ASC ? CLASSNAME_DESC : CLASSNAME_ASC
 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants