Skip to content

feat(table): allow sort by column#8353

Open
luka-nextcloud wants to merge 1 commit intomainfrom
sort-by-column
Open

feat(table): allow sort by column#8353
luka-nextcloud wants to merge 1 commit intomainfrom
sort-by-column

Conversation

@luka-nextcloud
Copy link
Contributor

@luka-nextcloud luka-nextcloud commented Mar 17, 2026

📝 Summary

🚧 TODO

  • ...

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests
  • Documentation (README or documentation) has been updated or is not required

@luka-nextcloud
Copy link
Contributor Author

🖼️ Screenshots

demo.webm

@codecov
Copy link

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 77.41935% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/nodes/Table/TableHeaderView.vue 0.00% 10 Missing ⚠️
src/nodes/Table/Table.js 92.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@max-nextcloud
Copy link
Collaborator

@luka-nextcloud Thanks a lot! That looks really great. I'll take a look at the code. Could you rebase and npm run prettier:fix on the branch to make prettier happy?

Thanks!

Copy link
Collaborator

@max-nextcloud max-nextcloud left a comment

Choose a reason for hiding this comment

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

All in all looks good.

I think it would be nice to not move the cursor around to change the sort order. I added some more detailed comments explaining how I think this would be feasible.

Comment on lines +277 to +295
const selectHeaderCell = (editor, targetIndex = 0) => {
let currentIndex = 0
let selectionPos
editor.state.doc.descendants((node, pos) => {
if (node.type.name !== 'tableHeader') {
return true
}
if (currentIndex === targetIndex) {
selectionPos = pos + 1
return false
}
currentIndex += 1
return true
})
if (selectionPos != null) {
editor.commands.setTextSelection(selectionPos)
}
return selectionPos
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should not need to set the text selection but you can use it to get the header cell position to provite to the command.

return true
},
sortColumn:
(direction = 'asc', explicitColumnIndex = null) =>
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice if this command did not depend on the cursor position. This would remove the need to move the cursor around just to change the sorting of a table.

So instead of getting the $cell from the state below we'd need to provide it as a function argument. I think the easiest would be to just provide the position of the cell as returned by this.getPos() inside the cell node and then find the cell from there.

This would also remove the need for the explicitColumnIndex - as the index would just be the index of the cell identified by the position.

Signed-off-by: Luka Trovic <luka@nextcloud.com>
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.

Table: allow to sort by column

2 participants