Skip to content

Commit be67d3e

Browse files
Modified new table example.
1 parent ac4126b commit be67d3e

1 file changed

Lines changed: 45 additions & 90 deletions

File tree

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

Lines changed: 45 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,88 +1001,66 @@ This will generate a table with the stores in the first column, and the items in
10011001
),
10021002
(
10031003
'table',
1004-
'# Using row based custom actions in a table
1004+
'## Using Action Buttons in a table.
10051005
1006-
The table has a column of buttons, each button defined by the `_sqlpage_actions` column at the table level, and by the `_sqlpage_actions` property at the row level.
1006+
### Preset Actions: `edit_url` & `delete_url`
1007+
Since edit and delete are common actions, the `table` component has dedicated `edit_url` and `delete_url` properties to add buttons for these actions.
1008+
The value of these properties should be a URL, containing the `{id}` placeholder that will be replaced by the value of the `_sqlpage_id` property for that row.
10071009
1008-
```sql
1009-
SELECT
1010-
name, vendor, product_number, facility_name,
1011-
lot_number, status, date_of_expiration,
1012-
--Use the unique identifier of the row as the _sqlpage_id property
1013-
standard_id AS _sqlpage_id,
1014-
--Build an array of objects, each object defining a button with the following properties: name, icon, link, tooltip
1015-
json_array(--SQLite specific, refer to your database documentation for the equivalent JSON functions
1016-
--The {id} placeholder in the link property will be replaced by the value of the _sqlpage_id property for that row.
1017-
json_object(''name'', ''history'', ''tooltip'', ''View Standard History'', ''link'', ''./history.sql?standard_id={id}'', ''icon'', ''history''),
1018-
json_object(''name'', ''view_coa'', ''tooltip'', ''View Certificate of Analysis'', ''link'', c_of_a_path, ''icon'', ''file-type-pdf''),
1019-
json_object(''name'', ''edit'', ''tooltip'', ''Edit Standard'', ''link'', ''./update.sql?id={id}'', ''icon'', ''pencil''),
1020-
--We want different actions based on the status of the standard, so we use a CASE statement to build the appropriate action
1021-
CASE
1022-
WHEN status = ''Available'' THEN json_object(
1023-
''name'',''Action'',
1024-
''tooltip'',''Set In Use'',
1025-
''link'',''./actions/set_in_use.sql?standard_id='' || standard_id,
1026-
''icon'',''caret-right''
1027-
)
1028-
WHEN status = ''In Use'' THEN json_object(
1029-
''name'',''Action'',
1030-
''tooltip'',''Retire Standard'',
1031-
''link'',''./actions/retire.sql?standard_id='' || standard_id,
1032-
''icon'',''test-pipe-off''
1033-
)
1034-
WHEN status = ''Retired'' THEN json_object(
1035-
''name'',''Action'',
1036-
''tooltip'',''Discard Standard'',
1037-
''link'',''./actions/discard.sql?standard_id='' || standard_id,
1038-
''icon'',''flask-off''
1039-
)
1040-
-- Include an action with no link or icon as a placeholder to keep the buttons aligned and make sure the header is correct.
1041-
WHEN status = ''Discarded'' THEN json_object(''name'',''Action'')
1042-
1043-
ELSE json_object(''name'',''Action'')
1044-
END
1045-
)
1046-
AS _sqlpage_actions
1047-
FROM standard;
1048-
1049-
```
1010+
### Column with fixed action buttons
10501011
1012+
You may want to add custom action buttons to your table rows, for instance to view details, download a file, or perform a custom operation.
1013+
For this, the `table` component has a `custom_actions` property that lets you define a column of buttons, each button defined by a name, an icon, a link, and an optional tooltip.
10511014
1052-
'
1015+
### Column with variable action buttons
1016+
1017+
The `table` component also supports the row level `_sqlpage_actions` column in your data table.
1018+
This is helpful if you want a more complex logic, for instance to disable a button on some rows, or to change the link or icon based on the row data.
1019+
1020+
> WARNING!
1021+
> If the number of array items in `_sqlpage_actions` is not consistent across all rows, the table may not render correctly.
1022+
> You can leave blank spaces by including an object with only the `name` property.
1023+
1024+
The table has a column of buttons, each button defined by the `_sqlpage_actions` column at the table level, and by the `_sqlpage_actions` property at the row level.
1025+
### `custom_actions` & `_sqlpage_actions` JSON properties.
1026+
Each button is defined by the following properties:
1027+
* `name`: sets the column header and the tooltip if no tooltip is provided,
1028+
* `tooltip`: text to display when hovering over the button,
1029+
* `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,
1030+
* `icon`: the tabler icon name or image link to display on the button
1031+
1032+
### Example using all of the above
1033+
'
10531034
,
10541035
json('[
10551036
{
1056-
"component": "table"
1037+
"component": "table",
1038+
"edit_url": "./update.sql?id={id}",
1039+
"delete_url": "./delete.sql?id={id}",
1040+
"custom_actions": [
1041+
{
1042+
"name": "history",
1043+
"tooltip": "View Standard History",
1044+
"link": "./history.sql?standard_id={id}",
1045+
"icon": "history"
1046+
}
1047+
]
10571048
},
10581049
{
10591050
"name": "CalStd",
10601051
"vendor": "PharmaCo",
10611052
"product_number": "P1234",
1062-
"facility_name": "A Plant",
10631053
"lot_number": "T23523",
10641054
"status": "Available",
10651055
"date_of_expiration": "2026-10-13",
10661056
"_sqlpage_id": 32,
10671057
"_sqlpage_actions": [
1068-
{
1069-
"name": "history",
1070-
"tooltip": "View Standard History",
1071-
"link": "./history.sql?standard_id={id}",
1072-
"icon": "history"
1073-
},
10741058
{
10751059
"name": "view_coa",
10761060
"tooltip": "View Certificate of Analysis",
1077-
"link": "/c_of_a\\2025-09-30_22h01m21s_B69baKoz.pdf",
1061+
"link": "/c_of_a/2025-09-30_22h01m21s_B69baKoz.pdf",
10781062
"icon": "file-type-pdf"
10791063
},
1080-
{
1081-
"name": "edit",
1082-
"tooltip": "Edit Standard",
1083-
"link": "./update.sql?id={id}",
1084-
"icon": "pencil"
1085-
},
10861064
{
10871065
"name": "Action",
10881066
"tooltip": "Set In Use",
@@ -1095,30 +1073,17 @@ The table has a column of buttons, each button defined by the `_sqlpage_actions`
10951073
"name": "CalStd",
10961074
"vendor": "PharmaCo",
10971075
"product_number": "P1234",
1098-
"facility_name": "A Plant",
10991076
"lot_number": "T2352",
11001077
"status": "In Use",
11011078
"date_of_expiration": "2026-10-14",
11021079
"_sqlpage_id": 33,
11031080
"_sqlpage_actions": [
1104-
{
1105-
"name": "history",
1106-
"tooltip": "View Standard History",
1107-
"link": "./history.sql?standard_id={id}",
1108-
"icon": "history"
1109-
},
11101081
{
11111082
"name": "view_coa",
11121083
"tooltip": "View Certificate of Analysis",
1113-
"link": "/c_of_a\\2025-09-30_22h05m13s_cP7gqMyi.pdf",
1084+
"link": "/c_of_a/2025-09-30_22h05m13s_cP7gqMyi.pdf",
11141085
"icon": "file-type-pdf"
11151086
},
1116-
{
1117-
"name": "edit",
1118-
"tooltip": "Edit Standard",
1119-
"link": "./update.sql?id={id}",
1120-
"icon": "pencil"
1121-
},
11221087
{
11231088
"name": "Action",
11241089
"tooltip": "Retire Standard",
@@ -1131,35 +1096,25 @@ The table has a column of buttons, each button defined by the `_sqlpage_actions`
11311096
"name": "CalStd",
11321097
"vendor": "PharmaCo",
11331098
"product_number": "P1234",
1134-
"facility_name": "A Plant",
11351099
"lot_number": "A123",
11361100
"status": "Discarded",
11371101
"date_of_expiration": "2026-09-30",
11381102
"_sqlpage_id": 31,
11391103
"_sqlpage_actions": [
1140-
{
1141-
"name": "history",
1142-
"tooltip": "View Standard History",
1143-
"link": "./history.sql?standard_id={id}",
1144-
"icon": "history"
1145-
},
11461104
{
11471105
"name": "view_coa",
11481106
"tooltip": "View Certificate of Analysis",
1149-
"link": "#",
1107+
"link": "025-09-30_22h01m21s_B439baKoz.pdf",
11501108
"icon": "file-type-pdf"
11511109
},
11521110
{
1153-
"name": "edit",
1154-
"tooltip": "Edit Standard",
1155-
"link": "./update.sql?id={id}",
1156-
"icon": "pencil"
1157-
},
1158-
null
1111+
"name": "Action"
1112+
}
11591113
]
11601114
}
1161-
]')
1162-
);
1115+
]'
1116+
)
1117+
);
11631118

11641119

11651120

0 commit comments

Comments
 (0)