Skip to content

Commit 92fec20

Browse files
committed
New initial_search_value property in the table component to pre-fill the search bar with a value. This allows to display the table rows that will initially be filtered out by the search bar.
1 parent 81c9041 commit 92fec20

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Add support for encrypted Microsoft SQL Server connections. This finally allows connecting to databases that refuse clear-text connections, such as those hosted on Azure.
77
- Easier json handling in databases without a native json type. SQLPage now detects when you use a json function in SQLite or MariaDB to generate a column, and automatically converts the resulting string to a json object. This allows easily using components that take json parameters (like the new columns component) in MariaDB and SQLite.
88
- Add a new optional `database_password` configuration option to set the password for the database connection separately from the connection string. This allows to keep the password separate from the connection string, which can be useful for security purposes, logging, and avoids having to percent-encode the password in the connection string.
9+
- New `initial_search_value` property in the table component to pre-fill the search bar with a value. This allows to display the table rows that will initially be filtered out by the search bar.
910

1011
## 0.29.0 (2024-09-25)
1112
- New columns component: `columns`. Useful to display a comparison between items, or large key figures to an user.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
682682
-- top level
683683
('sort', 'Make the columns clickable to let the user sort by the value contained in the column.', 'BOOLEAN', TRUE, TRUE),
684684
('search', 'Add a search bar at the top of the table, letting users easily filter table rows by value.', 'BOOLEAN', TRUE, TRUE),
685+
('initial_search_value', 'Pre-fills the search bar used to filter the table. The user will still be able to edit the value to display table rows that will initially be filtered out.', 'TEXT', TRUE, TRUE),
685686
('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),
686687
('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),
687688
('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),
@@ -715,10 +716,10 @@ INSERT INTO example(component, description, properties) VALUES
715716
'table',
716717
'A table with numbers',
717718
json(
718-
'[{"component":"table", "search": true, "sort": true, "align_right": ["Price ($)", "Amount in stock"]}, ' ||
719+
'[{"component":"table", "initial_search_value": "F-24", "sort": true, "align_right": ["Price ($)", "Amount in stock"]}, ' ||
719720
'{"id": 31456, "part_no": "MIC-ROCC-F-23-206-C", "Price ($)": 12, "Amount in stock": 5},
720721
{"id": 996, "part_no": "MIC-ROCC-F-24-206-A", "Price ($)": 1, "Amount in stock": 15},
721-
{"id": 131456, "part_no": "KIB-ROCC-F-13-205-B", "Price ($)": 127, "Amount in stock": 9}
722+
{"id": 131456, "part_no": "KIB-ROCC-F-24-205-B", "Price ($)": 127, "Amount in stock": 9}
722723
]'
723724
)),
724725
(

sqlpage/sqlpage.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ function sqlpage_card() {
2727
function sqlpage_table(){
2828
// Tables
2929
for (const r of document.querySelectorAll("[data-pre-init=table]")) {
30-
new List(r, {
30+
const list = new List(r, {
3131
valueNames: [...r.getElementsByTagName("th")].map(t => t.textContent),
3232
searchDelay: 100,
3333
// Hurts performance, but prevents https://github.com/lovasoa/SQLpage/issues/542
3434
// indexAsync: true
3535
});
36+
const search_input = r.querySelector("input.search");
37+
if (search_input && search_input.value) {
38+
list.search(search_input.value);
39+
}
3640
r.removeAttribute("data-pre-init");
3741
}
3842
}

sqlpage/templates/table.handlebars

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<div class="card my-2 {{class}}" {{#if overflow}}style="width: fit-content;"{{/if}} {{#if id}}id="{{id}}"{{/if}}>
22
<div class="card-body">
33
<div class="table-responsive" {{#if (or sort search)}}data-pre-init="table"{{/if}}>
4-
{{#if search}}
4+
{{#if (or search initial_search_value)}}
55
<div class="p-2">
6-
<input type="search" class="form-control form-control-rounded fs-6 search" placeholder="Search…">
6+
<input type="search" class="form-control form-control-rounded fs-6 search" placeholder="Search…"
7+
value="{{initial_search_value}}"
8+
{{#if initial_search_value}}autocomplete="off"{{/if}}
9+
>
710
</div>
811
{{/if}}
912
<table class="table {{#if striped_rows}}table-striped {{/if}}{{#if

0 commit comments

Comments
 (0)