Skip to content
Merged
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
72 changes: 72 additions & 0 deletions js/mdtablesort.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,69 @@ function injectSortStyles() {
document.head.appendChild(style);
}

// Parse numeric values optionally containing commas and units (e.g. 1,024, 10k, 5 MB/s).
function parseNumberWithUnits(value) {
if (value === null || value === undefined) return null;

// Remove thousands separators and normalize spacing
const cleaned = String(value).replace(/,/g, '').trim();
if (!cleaned) return null;

const match = cleaned.match(/^(-?\d+(?:\.\d+)?)(?:\s*([a-zA-Z]+(?:\/s)?|%))?$/);
if (!match) return null;

const numberPart = parseFloat(match[1]);
if (isNaN(numberPart)) return null;

const unit = (match[2] || '').toLowerCase();

const unitMultipliers = {
'': 1,
'%': 1,
'k': 1e3,
'kb': 1024,
'kib': 1024,
'kbyte': 1024,
'kbytes': 1024,
'kbit': 1e3,
'kbit/s': 1e3,
'kb/s': 1e3,
'kbps': 1e3,
'm': 1e6,
'mb': 1024 * 1024,
'mib': 1024 * 1024,
'mbyte': 1024 * 1024,
'mbytes': 1024 * 1024,
'mbit': 1e6,
'mbit/s': 1e6,
'mb/s': 1e6,
'mbps': 1e6,
'g': 1e9,
'gb': 1024 * 1024 * 1024,
'gib': 1024 * 1024 * 1024,
'gbyte': 1024 * 1024 * 1024,
'gbytes': 1024 * 1024 * 1024,
'gbit': 1e9,
'gbit/s': 1e9,
'gb/s': 1e9,
'gbps': 1e9,
't': 1e12,
'tb': 1024 * 1024 * 1024 * 1024,
'tib': 1024 * 1024 * 1024 * 1024,
'tbyte': 1024 * 1024 * 1024 * 1024,
'tbytes': 1024 * 1024 * 1024 * 1024,
'tbit': 1e12,
'tbit/s': 1e12,
'tb/s': 1e12,
'tbps': 1e12
};

const multiplier = unitMultipliers[unit];
if (multiplier === undefined) return null;

return numberPart * multiplier;
}

// Add helper function to support "yyyy-MM-dd HH:mm:ss" format.
function parseDate(str) {
// If the string contains a space but no 'T', replace the first space with 'T'
Expand Down Expand Up @@ -219,6 +282,15 @@ function sortTable(table) {
continue;
}

// Attempt parsing numbers with commas or units before falling back to strings
const parsedA = parseNumberWithUnits(valA);
const parsedB = parseNumberWithUnits(valB);
if (parsedA !== null && parsedB !== null) {
if (parsedA < parsedB) return crit.direction === 'asc' ? -1 : 1;
if (parsedA > parsedB) return crit.direction === 'asc' ? 1 : -1;
continue;
}

// Fallback to string comparison
if (valA < valB) return crit.direction === 'asc' ? -1 : 1;
if (valA > valB) return crit.direction === 'asc' ? 1 : -1;
Expand Down
Binary file removed lib/jetty-compression-common-12.1.4.jar
Binary file not shown.
Binary file added lib/jetty-compression-common-12.1.5.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<dependency>
<groupId>org.eclipse.jetty.compression</groupId>
<artifactId>jetty-compression-common</artifactId>
<version>12.1.4</version>
<version>12.1.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-jetty-common</artifactId>
<version>12.1.4</version>
<version>12.1.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
Expand All @@ -265,7 +265,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-jetty-client</artifactId>
<version>12.1.4</version>
<version>12.1.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
Expand All @@ -275,7 +275,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ma
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>jetty-websocket-core-common</artifactId>
<version>12.1.4</version>
<version>12.1.5</version>
</dependency>
<dependency>
<groupId>jline</groupId>
Expand Down