Skip to content

Commit c5d45c8

Browse files
committed
Add support for freeze_columns and freeze_headers in the table component
fixes #683
1 parent 3f51185 commit c5d45c8

File tree

4 files changed

+100
-5
lines changed

4 files changed

+100
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- Adds support for the `LIMIT max_rows, offset` syntax in SQLite. https://www.sqlite.org/lang_select.html#limitoffset
3131
- Adds support for `ANY`, `ALL`, and `SOME` subqueries, like `SELECT * FROM t WHERE a = ANY (SELECT b FROM t2)`
3232
- Add support for `change_percent` without `description` in the big_number component to display the percentage change of a value.
33+
- Add support for `freeze_columns` and `freeze_headers` in the table component to freeze columns and headers.
3334

3435
## 0.30.1 (2024-10-31)
3536
- fix a bug where table sorting would break if table search was not also enabled.

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
694694
('small', 'Whether to use compact table.', 'BOOLEAN', TRUE, TRUE),
695695
('description','Description of the table content and helps users with screen readers to find a table and understand what it’s.','TEXT',TRUE,TRUE),
696696
('empty_description', 'Text to display if the table does not contain any row. Defaults to "no data".', 'TEXT', TRUE, TRUE),
697+
('freeze_columns', 'Whether to freeze the leftmost column of the table.', 'BOOLEAN', TRUE, TRUE),
698+
('freeze_headers', 'Whether to freeze the top row of the table.', 'BOOLEAN', TRUE, TRUE),
697699
-- row level
698700
('_sqlpage_css_class', 'For advanced users. Sets a css class on the table row. Added in v0.8.0.', 'TEXT', FALSE, TRUE),
699701
('_sqlpage_color', 'Sets the background color of the row. Added in v0.8.0.', 'COLOR', FALSE, TRUE),
@@ -739,6 +741,68 @@ INSERT INTO example(component, description, properties) VALUES
739741
'table',
740742
'An empty table with a friendly message',
741743
json('[{"component":"table", "empty_description": "Nothing to see here at the moment."}]')
744+
),
745+
(
746+
'table',
747+
'A large table with many rows and columns, with frozen columns on the left and headers on top. This allows users to browse large datasets without loosing track of their position.',
748+
json('[
749+
{"component": "table", "freeze_columns": true, "freeze_headers": true},
750+
{
751+
"feature": "SQL Execution",
752+
"description": "Fully compatible with existing databases SQL dialects, executes any SQL query.",
753+
"benefits": "Short learning curve, easy to use, interoperable with existing tools."
754+
},
755+
{
756+
"feature": "Data Visualization",
757+
"description": "Automatic visualizations of query results: graphs, plots, pie charts, heatmaps, etc.",
758+
"benefits": "Quickly analyze data trends, attractive and easy to understand, no external visualization tools or languages to learn."
759+
},
760+
{
761+
"feature": "User Authentication",
762+
"description": "Supports user sessions, from basic auth to single sign-on.",
763+
"benefits": "Secure, enforces access control policies, and provides a customizable security layer."
764+
},
765+
{
766+
"feature": "APIs",
767+
"description": "Allows building JSON REST APIs and integrating with external APIs.",
768+
"benefits": "Enables automation and integration with other platforms, facilitates data exchange."
769+
},
770+
{
771+
"feature": "Files",
772+
"description": "File uploads, downloads and processing. Supports local filesystem and database storage.",
773+
"benefits": "Convenient file management, secure data handling, flexible storage options, integrates with existing systems."
774+
},
775+
{
776+
"feature": "Maps",
777+
"description": "Supports GeoJSON and is compatible with GIS data for map visualization.",
778+
"benefits": "Geospatial data representation, integrates with geographic information systems."
779+
},
780+
{
781+
"feature": "Custom Components",
782+
"description": "Build advanced features using HTML, JavaScript, and CSS.",
783+
"benefits": "Tailor-made user experiences, easy to implement custom UI requirements."
784+
},
785+
{
786+
"feature": "Forms",
787+
"description": "Insert and update data in databases based on user input.",
788+
"benefits": "Simplified data input and management, efficient user interactions with databases."
789+
},
790+
{
791+
"feature": "DB Compatibility",
792+
"description": "Works with MySQL, PostgreSQL, SQLite, Microsoft SQL Server and compatible databases.",
793+
"benefits": "Broad compatibility with popular database systems, ensures seamless integration."
794+
},
795+
{
796+
"feature": "Security",
797+
"description": "Built-in protection against common web vulnerabilities: no SQL injection, no XSS.",
798+
"benefits": "Passes audits and security reviews, reduces the risk of data breaches."
799+
},
800+
{
801+
"feature": "Performance",
802+
"description": "Designed for performance, with a focus on efficient data processing and minimal overhead.",
803+
"benefits": "Quickly processes large datasets, handles high volumes of requests, and minimizes server load."
804+
}
805+
]')
742806
),
743807
(
744808
'table',

sqlpage/sqlpage.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,27 @@ code {
6363
fill: var(--tblr-body-color) !important;
6464
font-weight: var(--tblr-body-font-weight);
6565
}
66+
67+
/** table **/
68+
.table-freeze-headers thead {
69+
position: sticky;
70+
top: 0;
71+
z-index: 2;
72+
}
73+
74+
.table-freeze-headers {
75+
max-height: 50vh;
76+
}
77+
78+
.table-freeze-columns th:first-child {
79+
position: sticky;
80+
left:0;
81+
z-index: 2;
82+
}
83+
84+
.table-freeze-columns td:first-child{
85+
position: sticky;
86+
left:0;
87+
background: var(--tblr-bg-surface-secondary);
88+
box-shadow: 3px 0 3px var(--tblr-border-color);
89+
}

sqlpage/templates/table.handlebars

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111
>
1212
</div>
1313
{{/if}}
14-
<div class="table-responsive">
15-
<table class="table {{#if striped_rows}}table-striped {{/if}}{{#if
16-
striped_columns}}table-striped-columns {{/if}}{{#if
17-
hover}}table-hover {{/if}}{{#if border}}table-bordered {{/if}}
18-
{{#if small}}table-sm {{/if}}">
14+
<div class="table-responsive
15+
{{~#if freeze_columns}} table-freeze-columns text-nowrap {{/if~}}
16+
{{~#if freeze_headers}} table-freeze-headers text-nowrap {{/if~}}
17+
">
18+
<table class="table
19+
{{~#if striped_rows}} table-striped {{/if~}}
20+
{{~#if striped_columns}} table-striped-columns {{/if~}}
21+
{{~#if hover}} table-hover {{/if~}}
22+
{{~#if border}} table-bordered {{/if~}}
23+
{{~#if small}} table-sm {{/if~}}
24+
">
1925
{{#if description}}<caption>{{description}}</caption>{{/if}}
2026
{{#each_row}}
2127
{{#if (eq @row_index 0)}}

0 commit comments

Comments
 (0)