Skip to content

Commit e17d3d0

Browse files
committed
add align_center to the table component
Closes #752
1 parent 521328f commit e17d3d0

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG.md
22

3+
## 0.32.1 (unreleased)
4+
5+
This is a bugfix release.
6+
7+
- Fix a bug where the form component would not display the right checked state in radio buttons and checkboxes.
8+
- https://github.com/sqlpage/SQLPage/issues/751
9+
310
## 0.32.0 (2024-12-29)
411

512
- Rollback any open transactions when an error occurs in a SQL file.

examples/official-site/sqlpage/migrations/01_documentation.sql

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,21 @@ We could also save all the options in a database table, and then run a simple qu
418418
419419
```sql
420420
SELECT ''form'' AS component;
421-
SELECT * FROM fruit_option;
421+
SELECT
422+
''radio'' as type,
423+
''db'' as name,
424+
option_name as label,
425+
option_id as value
426+
FROM my_options;
422427
```
423428
424-
In this example, depending on what the user clicks, the target `index.sql` page will be loaded with a the variable `$fruit` set to the string "1", "2", or "3".
429+
In this example, depending on what the user clicks, the page will be reloaded with a the variable `$component` set to the string "form", "map", or "chart".
425430
426-
', json('[{"component":"form", "method": "GET", "action": "index.sql"}, '||
427-
'{"name": "fruit", "type": "radio", "value": 1, "description": "An apple a day keeps the doctor away", "label": "Apple"}, '||
428-
'{"name": "fruit", "type": "radio", "value": 2, "description": "Oranges are a good source of vitamin C", "label": "Orange", "checked": true}, '||
429-
'{"name": "fruit", "type": "radio", "value": 3, "description": "Bananas are a good source of potassium", "label": "Banana"}'||
430-
']')),
431+
', json('[{"component":"form", "method": "GET"},
432+
{"name": "component", "type": "radio", "value": "form", "description": "Read user input in SQL", "label": "Form"},
433+
{"name": "component", "type": "radio", "value": "map", "checked": true, "description": "Display a map based on database data", "label": "Map"},
434+
{"name": "component", "type": "radio", "value": "chart", "description": "Interactive plots of SQL query results", "label": "Chart"}
435+
]')),
431436
('form', 'When you want to include some information in the form data, but not display it to the user, you can use a hidden field.
432437
433438
This can be used to track simple data such as the current user''s id,
@@ -722,6 +727,8 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
722727
('markdown', 'Set this to the name of a column whose content should be interpreted as markdown . Used to display rich text with links in the table. This argument can be repeated multiple times to intepret multiple columns as markdown.', 'TEXT', TRUE, TRUE),
723728
('icon', 'Set this to the name of a column whose content should be interpreted as a tabler icon name. Used to display icons in the table. This argument can be repeated multiple times to intepret multiple columns as icons. Introduced in v0.8.0.', 'TEXT', TRUE, TRUE),
724729
('align_right', 'Name of a column the contents of which should be right-aligned. This argument can be repeated multiple times to align multiple columns to the right. Introduced in v0.15.0.', 'TEXT', TRUE, TRUE),
730+
('align_center', 'Name of a column the contents of which should be center-aligned. This argument can be repeated multiple times to align multiple columns to the center.', 'TEXT', TRUE, TRUE),
731+
('monospace', 'Name of a column the contents of which should be displayed in monospace. This argument can be repeated multiple times to display multiple columns in monospace. Introduced in v0.32.1.', 'TEXT', TRUE, TRUE),
725732
('striped_rows', 'Whether to add zebra-striping to any table row.', 'BOOLEAN', TRUE, TRUE),
726733
('striped_columns', 'Whether to add zebra-striping to any table column.', 'BOOLEAN', TRUE, TRUE),
727734
('hover', 'Whether to enable a hover state on table rows.', 'BOOLEAN', TRUE, TRUE),
@@ -754,7 +761,7 @@ INSERT INTO example(component, description, properties) VALUES
754761
'table',
755762
'A table with column sorting. Sorting sorts numbers in numeric order, and strings in alphabetical order.',
756763
json(
757-
'[{"component":"table", "sort": true, "align_right": ["Price ($)", "Amount in stock"]}, ' ||
764+
'[{"component":"table", "sort": true, "align_right": ["Price ($)", "Amount in stock"], "align_center": ["part_no"], "monospace": ["part_no"]}, ' ||
758765
'{"id": 31456, "part_no": "MIC-ROCC-F-23-206-C", "Price ($)": 12, "Amount in stock": 5},
759766
{"id": 996, "part_no": "MIC-ROCC-F-24-206-A", "Price ($)": 1, "Amount in stock": 15},
760767
{"id": 131456, "part_no": "KIB-ROCC-F-24-205-B", "Price ($)": 127, "Amount in stock": 9}

sqlpage/templates/table.handlebars

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<th class="
3333
{{~@key~}}
3434
{{~#if (array_contains_case_insensitive ../../align_right @key)}} text-end {{/if~}}
35+
{{~#if (array_contains_case_insensitive ../../align_center @key)}} text-center {{/if~}}
3536
">
3637
{{~#if ../../sort~}}
3738
<button class="table-sort sort d-inline" data-sort="{{@key}}">{{@key}}</button>
@@ -51,9 +52,9 @@
5152
{{~#if (not (starts_with @key '_sqlpage_'))~}}
5253
<td class="
5354
{{~@key~}}
54-
{{~#if (array_contains_case_insensitive ../../align_right @key)
55-
}} text-end {{
56-
/if}} align-middle">
55+
{{~#if (array_contains_case_insensitive ../../align_right @key)}} text-end {{/if~}}
56+
{{~#if (array_contains_case_insensitive ../../align_center @key)}} text-center {{/if~}}
57+
align-middle">
5758
{{~#if (array_contains_case_insensitive ../../markdown @key)~}}
5859
{{{markdown this}}}
5960
{{~else~}}

0 commit comments

Comments
 (0)