diff --git a/examples/official-site/content/components/table.md b/examples/official-site/content/components/table.md new file mode 100644 index 000000000..57db5f1f9 --- /dev/null +++ b/examples/official-site/content/components/table.md @@ -0,0 +1,156 @@ +--- +icon: table +category: display-data +summary: Turn query results into a sortable, searchable table. +top: + - name: align_center + type: TEXT + description: 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. + - name: align_right + type: TEXT + description: 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. + - name: border + type: BOOLEAN + description: Whether to draw borders on all sides of the table and cells. + - class + - name: currency + type: TEXT + description: The ISO 4217 currency code (e.g., USD, EUR, GBP, etc.) to use when formatting monetary values. + - name: custom_actions + type: JSON + description: 'If set, a column of custom action buttons will be added to each row. The value of this property + should be a JSON array of objects, each object defining a button with the following properties: `name` + (the text to display on the button), `icon` (the tabler icon name or image link to display on the button), + `link` (the URL to navigate to when the button is clicked, possibly containing the `{id}` placeholder + that will be replaced by the value of the `_sqlpage_id` property for that row), and `tooltip` (optional + text to display when hovering over the button). Added in v0.39.0' + - name: delete_url + type: TEXT + description: If set, a delete button will be added to each row. The value of this property should be a + URL, possibly containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` + property for that row. Clicking the delete button will take the user to that URL. Added in v0.39.0 + - name: description + type: TEXT + description: Description of the table contents. Helps users with screen readers to find a table and understand + what it’s about. + - name: edit_url + type: TEXT + description: If set, an edit button will be added to each row. The value of this property should be a URL, + possibly containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` property + for that row. Clicking the edit button will take the user to that URL. Added in v0.39.0 + - name: embed + type: TEXT + description: Name of a column whose values are URLs to HTML fragments, such as other SQLPage pages. + Repeat this property to select multiple columns. The browser fetches each nonempty URL with + `_sqlpage_embed=1`, which skips the SQLPage shell, and initializes any components inside the cell. + Use only URLs whose HTML you trust. There is one request per populated cell. Sorting uses the original + URL, and search skips embedded cells. + - name: empty_description + type: TEXT + description: Text to display if the table does not contain any row. Defaults to "no data". + - name: freeze_columns + type: BOOLEAN + description: Whether to freeze the leftmost column of the table. + - name: freeze_footers + type: BOOLEAN + description: Whether to freeze the footer (bottom row) of the table, only works if that row has the `_sqlpage_footer` + property applied to it. + - name: freeze_headers + type: BOOLEAN + description: Whether to freeze the top row of the table. + - name: hover + type: BOOLEAN + description: Whether to enable a hover state on table rows. + - name: icon + type: TEXT + description: 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. + - id + - name: initial_search_value + type: TEXT + description: 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. + - name: markdown + type: TEXT + description: 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. + - name: money + type: TEXT + description: Name of a numeric column whose values should be displayed as currency amounts, in the currency + defined by the `currency` property. This argument can be repeated multiple times. + - name: monospace + type: TEXT + description: 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. + - name: number_format_digits + type: INTEGER + description: Maximum number of decimal digits to display for numeric values. + - name: number_format_locale + type: TEXT + description: A BCP 47 language tag (e.g. "de-DE", "en-IN") deciding how numbers and monetary values are + formatted. Defaults to the locale of the visitor's browser. + - name: overflow + type: BOOLEAN + description: Whether to to let "wide" tables overflow across the right border and enable browser-based + horizontal scrolling. + - name: raw_numbers + type: TEXT + description: Name of a column whose values are numeric, but should be displayed as raw numbers without + any formatting (no thousands separators, decimal separator is always a dot). This argument can be repeated + multiple times. + - name: search + type: BOOLEAN + description: Add a search bar at the top of the table, letting users easily filter table rows by value. + - name: search_placeholder + type: TEXT + description: Customizes the placeholder text shown in the search input field. Replaces the default "Search..." + with text that better describes what users should search for. + - name: small + type: BOOLEAN + description: Whether to use compact table. + - name: sort + type: BOOLEAN + description: Make the columns clickable to let the user sort by the value contained in the column. + - name: striped_columns + type: BOOLEAN + description: Whether to add zebra-striping to any table column. + - name: striped_rows + type: BOOLEAN + description: Whether to add zebra-striping to any table row. + - name: title + type: TEXT + description: A title displayed above the table. +row: + - name: _sqlpage_actions + type: JSON + description: 'Sets custom action buttons for this specific row in addition to any defined at the table + level, The value of this property should be a JSON array of objects, each object defining a button with + the following properties: `name` (the text to display on the button), `icon` (the tabler icon name or + image link to display on the button), `link` (the URL to navigate to when the button is clicked, possibly + containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` property for + that row), and `tooltip` (optional text to display when hovering over the button). Added in v0.39.0' + - name: _sqlpage_color + type: COLOR + description: Sets the background color of the row. Added in v0.8.0. + - name: _sqlpage_css_class + type: TEXT + description: For advanced users. Sets a css class on the table row. Added in v0.8.0. + - name: _sqlpage_footer + type: BOOLEAN + description: Sets this row as the table footer. It is recommended that this parameter is applied to the + last row. Added in v0.34.0. + - name: _sqlpage_id + type: TEXT + description: Sets the id of the html tabler row element. Allows you to make links targeting a specific + row in a table. +--- + +A table with optional filtering and sorting. +Unlike most others, this component does not have a fixed set of item properties, any property that is used will be rendered directly as a column in the table. +Tables can contain rich text, including images, links, and icons. Table rows can be styled with a background color, and the table can be made striped, hoverable, and bordered. + +Advanced users can apply custom styles to table columns using a CSS class with the same name as the column, and to table rows using the `_sqlpage_css_class` property. diff --git a/examples/official-site/content/components/table/examples/01-basic.md b/examples/official-site/content/components/table/examples/01-basic.md new file mode 100644 index 000000000..f510ed56f --- /dev/null +++ b/examples/official-site/content/components/table/examples/01-basic.md @@ -0,0 +1,10 @@ +--- +rows: + - component: table + - a: 1 + b: 2 + - a: 3 + b: 4 +--- + +The most basic table. diff --git a/examples/official-site/content/components/table/examples/02-filtering-and-sorting.md b/examples/official-site/content/components/table/examples/02-filtering-and-sorting.md new file mode 100644 index 000000000..55ddc3b74 --- /dev/null +++ b/examples/official-site/content/components/table/examples/02-filtering-and-sorting.md @@ -0,0 +1,15 @@ +--- +rows: + - component: table + sort: true + search: true + search_placeholder: Filter by name + - First Name: Ophir + Last Name: Lojkine + Pseudonym: lovasoa + - First Name: Linus + Last Name: Torvalds + Pseudonym: torvalds +--- + +A table of users with filtering and sorting. diff --git a/examples/official-site/content/components/table/examples/03-markdown-links.md b/examples/official-site/content/components/table/examples/03-markdown-links.md new file mode 100644 index 000000000..440668108 --- /dev/null +++ b/examples/official-site/content/components/table/examples/03-markdown-links.md @@ -0,0 +1,16 @@ +--- +rows: + - component: table + markdown: Name + icon: icon + search: true + - icon: table + name: '[Table](?component=table)' + description: Displays SQL results as a searchable table. + _sqlpage_color: red + - icon: timeline + name: '[Chart](?component=chart)' + description: Show graphs based on numeric data. +--- + +A table that uses markdown to display links diff --git a/examples/official-site/content/components/table/examples/04-embed.md b/examples/official-site/content/components/table/examples/04-embed.md new file mode 100644 index 000000000..2c73e9e63 --- /dev/null +++ b/examples/official-site/content/components/table/examples/04-embed.md @@ -0,0 +1,11 @@ +--- +rows: + - component: table + embed: Chart + - Starting number: 7 + Chart: /examples/chart.sql?n=7&color=blue + - Starting number: 13 + Chart: /examples/chart.sql?n=13&color=green +--- + +`embed: Chart` names the column to render. Each row supplies its own chart URL in `Chart`; an empty value leaves that cell empty. The browser requests each populated cell separately. diff --git a/examples/official-site/content/components/table/examples/05-totals-footer.md b/examples/official-site/content/components/table/examples/05-totals-footer.md new file mode 100644 index 000000000..21c8f7fc9 --- /dev/null +++ b/examples/official-site/content/components/table/examples/05-totals-footer.md @@ -0,0 +1,17 @@ +--- +rows: + - component: table + sort: true + - Person: Rudolph Lingens + Height: 190 + - Person: Jane Doe + Height: 150 + - Person: John Doe + Height: 200 + - _sqlpage_footer: true + _sqlpage_color: green + Person: Average + Height: 180 +--- + +A sortable table with a colored footer showing the average value of its entries. diff --git a/examples/official-site/content/components/table/examples/06-sorting.md b/examples/official-site/content/components/table/examples/06-sorting.md new file mode 100644 index 000000000..655db0105 --- /dev/null +++ b/examples/official-site/content/components/table/examples/06-sorting.md @@ -0,0 +1,34 @@ +--- +rows: + - component: table + sort: true + align_right: + - Price + - Amount in stock + align_center: + - part_no + raw_numbers: + - id + currency: USD + money: + - Price + - id: 31456 + part_no: SQL-TABLE-856-G + Price: 12 + Amount in stock: 5 + - id: 996 + part_no: SQL-FORMS-86-M + Price: 1 + Amount in stock: 1234 + - id: 131456 + part_no: SQL-CARDS-56-K + Price: 127 + Amount in stock: 98 +--- + +A table with column sorting. Sorting sorts numbers in numeric order, and strings in alphabetical order. + +Numbers can be displayed + - as raw digits without formatting using the `raw_numbers` property, + - as currency using the `money` property to define columns that contain monetary values and `currency` to define the currency, + - as numbers with a fixed maximum number of decimal digits using the `number_format_digits` property. diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 9eb93fb81..62fa74b28 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -424,97 +424,6 @@ to the path of the file you want to include, followed by `?_sqlpage_embed`. {"embed": "/examples/chart.sql?_sqlpage_embed" } ]')); -INSERT INTO component(name, icon, description) VALUES - ('table', 'table', 'A table with optional filtering and sorting. -Unlike most others, this component does not have a fixed set of item properties, any property that is used will be rendered directly as a column in the table. -Tables can contain rich text, including images, links, and icons. Table rows can be styled with a background color, and the table can be made striped, hoverable, and bordered. - -Advanced users can apply custom styles to table columns using a CSS class with the same name as the column, and to table rows using the `_sqlpage_css_class` property. -'); - -INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'table', * FROM (VALUES - -- top level - ('title', 'A title displayed above the table.', 'TEXT', TRUE, TRUE), - ('sort', 'Make the columns clickable to let the user sort by the value contained in the column.', 'BOOLEAN', TRUE, TRUE), - ('search', 'Add a search bar at the top of the table, letting users easily filter table rows by value.', 'BOOLEAN', TRUE, TRUE), - ('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), - ('search_placeholder', 'Customizes the placeholder text shown in the search input field. Replaces the default "Search..." with text that better describes what users should search for.', 'TEXT', TRUE, TRUE), - ('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), - ('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), - ('embed', 'Name of a column whose values are URLs to HTML fragments, such as other SQLPage pages. Repeat this property to select multiple columns. The browser fetches each nonempty URL with `_sqlpage_embed=1`, which skips the SQLPage shell, and initializes any components inside the cell. Use only URLs whose HTML you trust. There is one request per populated cell. Sorting uses the original URL, and search skips embedded cells.', 'TEXT', TRUE, TRUE), - ('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), - ('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), - ('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), - ('striped_rows', 'Whether to add zebra-striping to any table row.', 'BOOLEAN', TRUE, TRUE), - ('striped_columns', 'Whether to add zebra-striping to any table column.', 'BOOLEAN', TRUE, TRUE), - ('hover', 'Whether to enable a hover state on table rows.', 'BOOLEAN', TRUE, TRUE), - ('border', 'Whether to draw borders on all sides of the table and cells.', 'BOOLEAN', TRUE, TRUE), - ('overflow', 'Whether to to let "wide" tables overflow across the right border and enable browser-based horizontal scrolling.', 'BOOLEAN', TRUE, TRUE), - ('small', 'Whether to use compact table.', 'BOOLEAN', TRUE, TRUE), - ('description','Description of the table contents. Helps users with screen readers to find a table and understand what it’s about.','TEXT',TRUE,TRUE), - ('empty_description', 'Text to display if the table does not contain any row. Defaults to "no data".', 'TEXT', TRUE, TRUE), - ('freeze_columns', 'Whether to freeze the leftmost column of the table.', 'BOOLEAN', TRUE, TRUE), - ('freeze_headers', 'Whether to freeze the top row of the table.', 'BOOLEAN', TRUE, TRUE), - ('freeze_footers', 'Whether to freeze the footer (bottom row) of the table, only works if that row has the `_sqlpage_footer` property applied to it.', 'BOOLEAN', TRUE, TRUE), - ('raw_numbers', 'Name of a column whose values are numeric, but should be displayed as raw numbers without any formatting (no thousands separators, decimal separator is always a dot). This argument can be repeated multiple times.', 'TEXT', TRUE, TRUE), - ('money', 'Name of a numeric column whose values should be displayed as currency amounts, in the currency defined by the `currency` property. This argument can be repeated multiple times.', 'TEXT', TRUE, TRUE), - ('currency', 'The ISO 4217 currency code (e.g., USD, EUR, GBP, etc.) to use when formatting monetary values.', 'TEXT', TRUE, TRUE), - ('number_format_digits', 'Maximum number of decimal digits to display for numeric values.', 'INTEGER', TRUE, TRUE), - ('number_format_locale', 'A BCP 47 language tag (e.g. "de-DE", "en-IN") deciding how numbers and monetary values are formatted. Defaults to the locale of the visitor''s browser.', 'TEXT', TRUE, TRUE), - ('edit_url', 'If set, an edit button will be added to each row. The value of this property should be a URL, possibly containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` property for that row. Clicking the edit button will take the user to that URL. Added in v0.39.0', 'TEXT', TRUE, TRUE), - ('delete_url', 'If set, a delete button will be added to each row. The value of this property should be a URL, possibly containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` property for that row. Clicking the delete button will take the user to that URL. Added in v0.39.0', 'TEXT', TRUE, TRUE), - ('custom_actions', 'If set, a column of custom action buttons will be added to each row. The value of this property should be a JSON array of objects, each object defining a button with the following properties: `name` (the text to display on the button), `icon` (the tabler icon name or image link to display on the button), `link` (the URL to navigate to when the button is clicked, possibly containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` property for that row), and `tooltip` (optional text to display when hovering over the button). Added in v0.39.0', 'JSON', TRUE, TRUE), - -- row level - ('_sqlpage_css_class', 'For advanced users. Sets a css class on the table row. Added in v0.8.0.', 'TEXT', FALSE, TRUE), - ('_sqlpage_color', 'Sets the background color of the row. Added in v0.8.0.', 'COLOR', FALSE, TRUE), - ('_sqlpage_footer', 'Sets this row as the table footer. It is recommended that this parameter is applied to the last row. Added in v0.34.0.', 'BOOLEAN', FALSE, TRUE), - ('_sqlpage_id', 'Sets the id of the html tabler row element. Allows you to make links targeting a specific row in a table.', 'TEXT', FALSE, TRUE), - ('_sqlpage_actions', 'Sets custom action buttons for this specific row in addition to any defined at the table level, The value of this property should be a JSON array of objects, each object defining a button with the following properties: `name` (the text to display on the button), `icon` (the tabler icon name or image link to display on the button), `link` (the URL to navigate to when the button is clicked, possibly containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` property for that row), and `tooltip` (optional text to display when hovering over the button). Added in v0.39.0', 'JSON', FALSE, TRUE) -) x; - -INSERT INTO example(component, description, properties) VALUES - ('table', 'The most basic table.', - json('[{"component":"table"}, {"a": 1, "b": 2}, {"a": 3, "b": 4}]')), - ('table', 'A table of users with filtering and sorting.', - json('[ - {"component":"table", "sort":true, "search":true, "search_placeholder": "Filter by name"}, - {"First Name": "Ophir", "Last Name": "Lojkine", "Pseudonym": "lovasoa"}, - {"First Name": "Linus", "Last Name": "Torvalds", "Pseudonym": "torvalds"} - ]')), - ('table', 'A table that uses markdown to display links', - json('[{"component":"table", "markdown": "Name", "icon": "icon", "search": true}, '|| - '{"icon": "table", "name": "[Table](?component=table)", "description": "Displays SQL results as a searchable table.", "_sqlpage_color": "red"}, - {"icon": "timeline", "name": "[Chart](?component=chart)", "description": "Show graphs based on numeric data."} - ]')), - ('table', '`embed: Chart` names the column to render. Each row supplies its own chart URL in `Chart`; an empty value leaves that cell empty. The browser requests each populated cell separately.', - json('[ - {"component": "table", "embed": "Chart"}, - {"Starting number": 7, "Chart": "/examples/chart.sql?n=7&color=blue"}, - {"Starting number": 13, "Chart": "/examples/chart.sql?n=13&color=green"} - ]')), - ('table', 'A sortable table with a colored footer showing the average value of its entries.', - json('[{"component":"table", "sort":true}, '|| - '{"Person": "Rudolph Lingens", "Height": 190},' || - '{"Person": "Jane Doe", "Height": 150},' || - '{"Person": "John Doe", "Height": 200},' || - '{"_sqlpage_footer":true, "_sqlpage_color": "green", "Person": "Average", "Height": 180}]')), - ( - 'table', - 'A table with column sorting. Sorting sorts numbers in numeric order, and strings in alphabetical order. - -Numbers can be displayed - - as raw digits without formatting using the `raw_numbers` property, - - as currency using the `money` property to define columns that contain monetary values and `currency` to define the currency, - - as numbers with a fixed maximum number of decimal digits using the `number_format_digits` property. -', - json( - '[{"component":"table", "sort": true, "align_right": ["Price", "Amount in stock"], "align_center": ["part_no"], "raw_numbers": ["id"], "currency": "USD", "money": ["Price"] }, - {"id": 31456, "part_no": "SQL-TABLE-856-G", "Price": 12, "Amount in stock": 5}, - {"id": 996, "part_no": "SQL-FORMS-86-M", "Price": 1, "Amount in stock": 1234}, - {"id": 131456, "part_no": "SQL-CARDS-56-K", "Price": 127, "Amount in stock": 98} - ]' - )); - INSERT INTO component(name, icon, description) VALUES diff --git a/examples/official-site/sqlpage/migrations/82_reference_catalog.sql b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql index 4bb285035..1de4bb488 100644 --- a/examples/official-site/sqlpage/migrations/82_reference_catalog.sql +++ b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql @@ -33,7 +33,6 @@ WITH copy(name, category, summary) AS (VALUES ('datagrid', 'display-data', 'Lay out labeled values in a compact grid.'), ('list', 'display-data', 'Present rows as a vertical list with optional links and icons.'), ('map', 'display-data', 'Plot locations and geographic shapes on an interactive map.'), - ('table', 'display-data', 'Turn query results into a sortable, searchable table.'), ('timeline', 'display-data', 'Arrange events along a vertical timeline.'), ('tracking', 'display-data', 'Show a sequence of activity or status changes as colored segments.'), diff --git a/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql b/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql index 65abff8ee..b3094f48d 100644 --- a/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql +++ b/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql @@ -24,7 +24,6 @@ FROM (VALUES ('list', TRUE), ('list', FALSE), ('map', TRUE), - ('table', TRUE), ('timeline', TRUE), ('timeline', FALSE), ('tracking', TRUE), @@ -44,7 +43,6 @@ FROM (VALUES ('list', TRUE), ('list', FALSE), ('map', TRUE), - ('table', TRUE), ('timeline', TRUE), ('timeline', FALSE), ('tracking', TRUE),