Skip to content

Conversation

@daiplusplus
Copy link

@daiplusplus daiplusplus commented Jun 11, 2022

In a recent project I need to show or hide certain table content based on which column the user wants to sort-by. Currently I'm only able to do this in the afterSort event by inspecting the <thead> for tr > *[aria-sort] - but this isn't ideal.

Ideally I'd like to filter/edit data in the beforeSort event, however this isn't possible because the beforeSort event is raised before the aria-sort="" attributes are updated and no useful data (other than the this reference to the HTMLTableElement) is included in the Event object.

...so this PR uses CustomEvent's detail property to allow the listener of afterSort and beforeSort to get the header (<th>) and update values.

I've also added a new event: sortCanceled, as the tableSort function will simply return (without providing any indication to the consuming page/application's script that it was aborted) after calling beforeSort if there's no data to sort, which I think violates expectations about the pairing of events.

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