Skip to content

Commit c73ff58

Browse files
committedDec 6, 2024
Fix a bug where the table component would not sort columns that contained a space in their name
Fixes #724
1 parent 49acd4a commit c73ff58

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed
 

Diff for: ‎CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
CREATE TEMPORARY TABLE t (x int) ON COMMIT DROP; -- postgres syntax
1111
-- do something with t
1212
-- previously, if an error occurred, the transaction would be left open, and the connection returned to the pool.
13-
-- the next request could get a connection where the table `t` still exists, leading to a new error.
13+
-- the next request could get a connection where the table `t` still exists, leading to a new hard to debug error.
1414
COMMIT;
1515
```
1616
- This will now automatically rollback the transaction, even if an error occurs in the middle of it.
@@ -24,6 +24,7 @@
2424
- Add a new optional `sqlpage/on_reset.sql` file that can be used to execute some SQL code after the end of each page execution.
2525
- Useful to reset a connection to the database after each request.
2626
- Fix a bug where the `sqlpage.header` function would not work with headers containing uppercase letters.
27+
- Fix a bug where the table component would not sort columns that contained a space in their name.
2728

2829
## 0.31.0 (2024-11-24)
2930

Diff for: ‎examples/official-site/sqlpage/migrations/01_documentation.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -736,8 +736,8 @@ INSERT INTO example(component, description, properties) VALUES
736736
json('[{"component":"table"}, {"a": 1, "b": 2}, {"a": 3, "b": 4}]')),
737737
('table', 'A table of users with filtering and sorting.',
738738
json('[{"component":"table", "sort":true, "search":true}, '||
739-
'{"Forename": "Ophir", "Surname": "Lojkine", "Pseudonym": "lovasoa"},' ||
740-
'{"Forename": "Linus", "Surname": "Torvalds", "Pseudonym": "torvalds"}]')),
739+
'{"First Name": "Ophir", "Last Name": "Lojkine", "Pseudonym": "lovasoa"},' ||
740+
'{"First Name": "Linus", "Last Name": "Torvalds", "Pseudonym": "torvalds"}]')),
741741
('table', 'A table that uses markdown to display links',
742742
json('[{"component":"table", "markdown": "Name", "icon": "icon", "search": true}, '||
743743
'{"icon": "table", "name": "[Table](?component=table)", "description": "Displays SQL results as a searchable table.", "_sqlpage_color": "red"},

Diff for: ‎sqlpage/sqlpage.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,16 @@ function table_search_sort(el) {
2727
const search_input = el.querySelector("input.search");
2828
const sort_buttons = [...el.querySelectorAll("button.sort[data-sort]")];
2929
const item_parent = el.querySelector("tbody");
30-
const items = [...item_parent.querySelectorAll("tr")].map((el) => ({
31-
el,
32-
sort_keys: sort_buttons.map((b) => {
33-
const sort_key = el.getElementsByClassName(b.dataset.sort)[0]
34-
?.textContent;
35-
return { num: Number.parseFloat(sort_key), str: sort_key };
36-
}),
37-
}));
30+
const items = [...item_parent.querySelectorAll("tr")].map((el) => {
31+
const cells = el.getElementsByTagName("td");
32+
return {
33+
el,
34+
sort_keys: sort_buttons.map((b, idx) => {
35+
const sort_key = cells[idx]?.textContent;
36+
return { num: Number.parseFloat(sort_key), str: sort_key };
37+
}),
38+
};
39+
});
3840
function onSearch() {
3941
const lower_search = search_input.value
4042
.toLowerCase()

0 commit comments

Comments
 (0)