Skip to content
Merged

Dev #89

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.1.6] - 2025-10-21

### Fixed

- The a11y module no longer marks columns with class="no-sort" as sortable

## [4.1.5] - 2025-10-16

### Changed
Expand Down Expand Up @@ -202,6 +208,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- First release

[4.1.6]: https://github.com/tofsjonas/sortable/releases/tag/4.1.6
[4.1.5]: https://github.com/tofsjonas/sortable/releases/tag/4.1.5
[4.1.4]: https://github.com/tofsjonas/sortable/releases/tag/4.1.4
[4.1.3]: https://github.com/tofsjonas/sortable/releases/tag/4.1.3
Expand Down
372 changes: 372 additions & 0 deletions dist/auto.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,372 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>sortable test</title>

<link rel="stylesheet" href="/example.css">
</head>
<body>
<h1>Sortable examples</h1>

<h2>Basic sort</h2>
<table class="sortable">
<thead>
<tr>
<th><span>Role</span></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td><a href="javascript:alert('Inline javascript works!');">Sidekick</a></td>
<td><a id="morty" href="#">Morty</a></td>
</tr>
</tbody>
</table>

<h2>Tiebreaker</h2>
<p>Sort by year</p>

(Appearance manually changed using style attributes. Just for demonstration.)

<pre style="background: #ddd; width: 180px; padding: 0.5em; border-radius: 0.5em; color: #000">
style="
--stripe-bg: #ff0;
--stripe-color: #000;
--stripe-bg-odd: #f0f;
--stripe-color-odd: #111;
--th-bg: blue;
--th-color: #fff;"</pre
>
<table
class="sortable"
style="
--stripe-bg: #ff0;
--stripe-color: #000;
--stripe-bg-odd: #f0f;
--stripe-color-odd: #111;
--th-bg: blue;
--th-color: #fff;
"
>
<thead>
<tr>
<th data-sort-tbr="2">Month</th>
<th data-sort-tbr="0">Year</th>
<th data-sort-tbr="3">Day</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>11</td>
<td>2010</td>
<td>25</td>
<td>12:00</td>
</tr>
<tr>
<td>11</td>
<td>2010</td>
<td>25</td>
<td>15:00</td>
</tr>
<tr>
<td>04</td>
<td>2010</td>
<td>12</td>
<td>13:00</td>
</tr>
</tbody>
</table>
<ul style="padding-left: 1.5em; font-style: italic">
<li>If year is the same, sort by month.</li>
<li>If month is the same, sort by day.</li>
<li>If day is the same, sort by time</li>
</ul>

<h2>Colspans</h2>

<table class="sortable sticky">
<thead>
<tr>
<th colspan="2">nums + chars</th>
<th data-sort-col="2">CHARS</th>
</tr>
</thead>
<tbody>
<tr>
<td>333</td>
<td>222</td>
<td>BB</td>
</tr>
<tr>
<td>1</td>
<td>111</td>
<td>CCC</td>
</tr>
<tr>
<td>22</td>
<td>333</td>
<td>A</td>
</tr>
</tbody>
</table>

<h2>Empty/null sorted last</h2>

<table class="sortable n-last lefty">
<thead>
<tr>
<th>Text</th>
<th class="indicator-left">Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>jkl</td>
<td>0.4</td>
</tr>
<tr>
<td>abc</td>
<td>0</td>
</tr>
<tr>
<td>should be sorted last</td>
<td data-sort="">(if click in this column)</td>
</tr>
<tr>
<td>def</td>
<td>0.2</td>
</tr>
</tbody>
</table>

<h2>class="no-sort"</h2>

<table class="sortable">
<thead>
<tr>
<th>Role</th>
<th class="no-sort">Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td>Sidekick</td>
<td>Morty</td>
</tr>
</tbody>
</table>

<h2>numeric sorting</h2>
<table class="sortable">
<thead>
<tr>
<th>Role</th>
<th>Time</th>
<th>Amount</th>
<th>Number</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>12:00:12</td>
<td>$18.49</td>
<td>2.49</td>
</tr>
<tr>
<td>Sidekick</td>
<td>12:22:11</td>
<td>$2.49</td>
<td>18.49</td>
</tr>
<tr>
<td>Butler</td>
<td>12:22:05</td>
<td>$1.96</td>
<td>1.96</td>
</tr>
</tbody>
</table>

<h2>Ascending sort</h2>

<table class="sortable asc">
<thead>
<tr>
<th><span>Role</span></th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td><a href="javascript:alert('Inline javascript works!');">Sidekick</a></td>
<td><a id="morty" href="#">Morty</a></td>
</tr>
</tbody>
</table>

<h2>Alternative sort</h2>

<table class="sortable">
<thead>
<tr>
<th>Movie Name</th>
<th>Size</th>
</tr>
</thead>
<tbody>
<tr>
<td data-sort-alt="c" data-sort="a">A</td>
<td data-sort-alt="b" data-sort="c">B</td>
</tr>
<tr>
<td data-sort-alt="e" data-sort="f">D</td>
<td data-sort-alt="f" data-sort="a">E</td>
</tr>
<tr>
<td data-sort-alt="k" data-sort="b">J</td>
<td data-sort-alt="j" data-sort="h">K</td>
</tr>
</tbody>
</table>

<h2>TR element with no TD element (invalid HTML)</h2>

<table class="sortable">
<thead>
<tr>
<th>Letters</th>
</tr>
</thead>
<tbody>
<tr>
<td>CCC</td>
</tr>
<tr></tr>
<!-- TR element has no child TD elements -->
<tr>
<td>DDD</td>
</tr>
<tr>
<td>AAA</td>
</tr>
</tbody>
</table>

<h2>TD with "incorrect" whitespace</h2>

<table class="sortable">
<thead>
<tr>
<th>Role</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Genius</td>
<td>Rick</td>
</tr>
<tr>
<td>&nbsp;Sidekick</td>
<td>Morty</td>
</tr>
</tbody>
</table>

<h2>HTML Tag Support</h2>

<table class="sortable">
<thead>
<tr>
<th>Event</th>
<th>Date</th>
<th>Progress</th>
<th>Score</th>
<th>Abbreviation</th>
</tr>
</thead>
<tbody>
<tr>
<td>Meeting</td>
<td><time datetime="2024-03-15">March 15, 2024</time></td>
<td><progress value="75" max="100">75%</progress></td>
<td><meter value="8.5" min="0" max="10">8.5/10</meter></td>
<td><abbr title="World Wide Web">WWW</abbr></td>
</tr>
<tr>
<td>Conference</td>
<td><time datetime="2024-01-10">January 10, 2024</time></td>
<td><progress value="50" max="100">50%</progress></td>
<td><meter value="9.2" min="0" max="10">9.2/10</meter></td>
<td><abbr title="Application Programming Interface">API</abbr></td>
</tr>
<tr>
<td>Workshop</td>
<td><time datetime="2024-12-01">December 1, 2024</time></td>
<td><progress value="90" max="100">90%</progress></td>
<td><meter value="7.8" min="0" max="10">7.8/10</meter></td>
<td><abbr title="Hypertext Markup Language">HTML</abbr></td>
</tr>
<tr>
<td>Seminar</td>
<td><time datetime="2024-06-20">June 20, 2024</time></td>
<td><progress max="100">Unknown</progress></td>
<td><data value="6.5">Six point five</data></td>
<td><abbr title="Cascading Style Sheets">CSS</abbr></td>
</tr>
</tbody>
</table>

<script>
document.getElementById('morty').addEventListener('click', function (e) {
e.preventDefault()
alert('event listeners also work!')
})
// Add a table, so we can test the MutationObserver
setTimeout(() => {
const table = document.createElement('table')
table.classList.add('sortable')
table.innerHTML = `
<thead>
<tr>
<th aria-sort="ascending">Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr><td>John Doe</td><td>30</td></tr>
<tr><td>Jane Smith</td><td>25</td></tr>
</tbody>
`
const div = document.createElement('div')
div.innerHTML = `<h2>MutationObserver Test</h2>
<p>This table was added using setTimeout. It will be sorted by default when using the <b>sortable.auto.js</b> package.</p>`
document.body.insertBefore(div, document.body.firstChild)
// If I append the the table to the div before appending it to the body,
// the MutationObserver will not trigger, since we are adding a div, not a table..
div.appendChild(table)
}, 2000) // Long delay so you can see the table being added
</script>


<script src="/sortable.auto.js"></script>
</body>
</html>
Loading
Loading