BloX Sort Values Action

Challenge:
When making a BloX widget, there is no UI element that you can use to sort the widget.
Solution:
This custom BloX action allows you to trigger a sort for any widgets including itself.
Steps To Implement:
STEP 1A: CREATING THE ACTION
Create the action using the following code and name it "sort value"
var widgetIds = payload.data.widgetToSort
var valueIndexToSort = payload.data.valueIndexToSort
var sortOrder = payload.data.sortDirection
payload.widget.dashboard.widgets.$$widgets
.filter(i => widgetIds.includes(i.oid))
.forEach(function (widget) {
// delete all sorts
widget.metadata.panels[1].items.forEach(function (i) {
if (i.jaql.hasOwnProperty('sort')) {
delete i.jaql.sort
}
})
// add new sort
widget.metadata.panels[1].items[valueIndexToSort].jaql.sort = sortOrder
widget.changesMade()
widget.refresh()
})
STEP 1B: CREATING THE ACTION SNIPPET
In Step 2 of 2 Create Action Snippet add the following snippet:
{
"type": "sort value",
"title": "sort",
"data": {
"widgetToSort": "enter ID here",
"sortDirection": "choose desc/asc",
"valueIndexToSort": "0"
}
}
STEP 2: IMPLEMENTING THE ACTION
In the example gif, the clickable element was used. You can find it in the action snippets.

You can also use this action in a standard action button.
Here is the code for the clickable element:
{
"type": "TextBlock",
"text": "⬆",
"selectAction": {
"type": "sort value",
"title": "sort",
"data": {
"widgetToSort": "5f1a0895fb660605bcc72a3a",
"sortDirection": "asc",
"valueIndexToSort": "0"
}
}
}
Updated 03-02-2023
intapiuser
Admin
Joined December 15, 2022