Save and apply filters on an Alarm Tableο
This example aims to demonstrate how you could use a collection to store the current filters of an Alarm Table in order to allow the user to use them to quickly filter a table. This could be useful if you have users that tend to redo the same filters on a table everyday. In this example, every filter saved in the collection is available for every user of the platform, but you could expand on this by using collections rights to limit the access of each user to only the ones they created or by any other condition.
git checkout origin/osp-alarms-configuration .
git checkout origin/osp-web-configuration .
git checkout origin/osp-scripts-configuration .
git checkout origin/osp-collections-configuration .
git checkout origin/example-dashboard-alarm-table-copy-filters .
Stepsο
1. Define the filters collectionο
The filters collections is the one that will contain all the saved filters from any users. We need:
name: Name to identify the filter
filters: copy of the filters from the table.
The filters must match what the alarm table produces. Therefore, filters is declarer as an array of objects with:
columnName: name of the table column
operation: operation of the filter (equal, contains, less than, β¦)
value: value of the filter
root/alarm_copy_filters/collections/filters/schema.ospp
{
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"filters": {
"type": "array",
"items": {
"type": "object",
"properties": {
"columnName": {
"type": "string"
},
"operation": {
"type": "string"
},
"value": {
"oneOf": [
{
"type": [
"string",
"number",
"boolean"
]
},
{
"type": "array",
"items": {
"type": [
"string",
"number",
"boolean"
]
}
}
]
}
}
}
}
}
},
"uniqueFields": [
"name"
],
"filters": [
{
"id": "all",
"name": "All"
}
]
}
We will also make a dashboard with a Collection Table in order to delete or edit the filters. We will define a form for this collection with a Json render to easily display the filters. For the delete menu, you can simply follow the Add a delete menu to a CollectionTable example.
root/alarm_copy_filters/form/filters/form.web
{
"moduleId": [
"modules.web.web-1"
],
"name": "Alarms filters",
"description": "Alarms filters",
"schema": "root.alarm_copy_filters.collections.filters",
"ui": {
"type": "VerticalLayout",
"elements": [
{
"type": "Group",
"elements": [
{
"type": "Control",
"scope": "#/properties/name"
}
]
},
{
"type": "Group",
"label": "Filtres",
"elements": [
{
"type": "Json",
"scope": "#/properties/filters"
}
]
}
]
},
"initialValue": {
"filters": []
},
"submit": {
"type": "Deferred",
"destination": "Request"
}
}
Additional notesο
Itβs noteworthy that any filter saved into the collection could then be use on any table. We could implement the same functionality for a Collection Table as well, as they both expose the necessary values from their context.