Skip to content

Commit bbeba21

Browse files
npm release 1.9.0
1 parent 401563d commit bbeba21

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

npm/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ Refer to the documenation for examples how to use table-sort-js with [HTML.](htt
5050
| <th> classes | Description |
5151
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
5252
| "order-by-desc" | Order by descending on first click. (default is aescending) |
53-
| "file-size" | Sort file sizes(B->TiB) uses the binary prefix. (e.g KiB) |
5453
| "data-sort" | Sort by [data attributes](https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes), e.g <td data-sort="42"> |
55-
| "disable-sort" | Disallow sorting the table by this specific column
54+
| "file-size-sort" | Sort file sizes(B->TiB) uses the binary prefix. (e.g KiB) |
55+
| "alpha-sort" | Sort alphabetically (z11,z2); default is [natural sort](https://en.wikipedia.org/wiki/Natural_sort_order) (z2,z11). |
56+
| "punct-sort" | Sort punctuation; default ignores punctuation. |
57+
| "disable-sort" | Disallow sorting the table by this specific column. |
5658

5759
#### Development:
5860

npm/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "table-sort-js",
3-
"version": "1.8.2",
3+
"version": "1.9.0",
44
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.",
55
"license": "MIT",
66
"repository": "LeeWannacott/table-sort-js",

npm/table-sort.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
207207
}
208208
}
209209

210-
function naturalSortAscending(a, b) {
210+
const isPunctSort = th.classList.contains("punct-sort");
211+
const isAlphaSort = th.classList.contains("alpha-sort");
212+
function sortAscending(a, b) {
211213
if (a.includes(`${fillValue}#`)) {
212214
return 1;
213215
} else if (b.includes(`${fillValue}#`)) {
@@ -216,13 +218,13 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
216218
return a.localeCompare(
217219
b,
218220
navigator.languages[0] || navigator.language,
219-
{ numeric: true, ignorePunctuation: true }
221+
{ numeric: !isAlphaSort, ignorePunctuation: !isPunctSort }
220222
);
221223
}
222224
}
223225

224-
function naturalSortDescending(a, b) {
225-
return naturalSortAscending(b, a);
226+
function sortDescending(a, b) {
227+
return sortAscending(b, a);
226228
}
227229

228230
function clearArrows(arrowUp = "▲", arrowDown = "▼") {
@@ -243,27 +245,27 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
243245

244246
function sortColumn(sortDirection) {
245247
columnData.sort(sortDirection, {
246-
numeric: true,
247-
ignorePunctuation: true,
248+
numeric: !isAlphaSort,
249+
ignorePunctuation: !isPunctSort,
248250
});
249251
}
250252

251253
if (timesClickedColumn === 1) {
252254
if (desc) {
253255
changeTableArrow(arrowDown);
254-
sortColumn(naturalSortDescending);
256+
sortColumn(sortDescending);
255257
} else {
256258
changeTableArrow(arrowUp);
257-
sortColumn(naturalSortAscending);
259+
sortColumn(sortAscending);
258260
}
259261
} else if (timesClickedColumn === 2) {
260262
timesClickedColumn = 0;
261263
if (desc) {
262264
changeTableArrow(arrowUp);
263-
sortColumn(naturalSortAscending);
265+
sortColumn(sortAscending);
264266
} else {
265267
changeTableArrow(arrowDown);
266-
sortColumn(naturalSortDescending);
268+
sortColumn(sortDescending);
267269
}
268270
}
269271
}
@@ -355,7 +357,7 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
355357
sortDataAttributes(visibleTableRows, columnData);
356358
}
357359

358-
const isFileSize = th.classList.contains("file-size");
360+
const isFileSize = th.classList.contains("file-size-sort");
359361
if (isFileSize) {
360362
sortFileSize(visibleTableRows, columnData);
361363
}

0 commit comments

Comments
 (0)