Clarification on Sortable tables #4941
-
This section explains how to use to tablesort and gives a demo. I don't understand how tablesort was switched on for the last table only but not the other tables in the same markdown files. If tablesort is natively integrated with Material for MkDocs then shouldn't all tables be sortable by default? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you view the source of the page (button at the top) and scroll down, you will see that we only apply table sorting to the last of the tables. In our documentation, we need to jump through some hoops to distinctively advertise some features. If all tables were sortable, there would be no point in advertising this to the user 😊 You can change the CSS selector to something that only targets the tables that you want to be sortable, or adjust the function that loops through all tables mounting document$.subscribe(function() {
var tables = document.querySelectorAll("article table:not([class])")
tables.forEach(function(table) {
new Tablesort(table)
})
}) The "native integration" refers to the icons rendering when hovering table cells. It still needs to be provided by the author, since bundling optional JavaScript would only increase loading times for everyone, albeit only a handful of authors using it. |
Beta Was this translation helpful? Give feedback.
If you view the source of the page (button at the top) and scroll down, you will see that we only apply table sorting to the last of the tables. In our documentation, we need to jump through some hoops to distinctively advertise some features. If all tables were sortable, there would be no point in advertising this to the user 😊
You can change the CSS selector to something that only targets the tables that you want to be sortable, or adjust the function that loops through all tables mounting
Tablesort
. As always with customizations, YMMV: