Last active
March 9, 2023 04:04
-
-
Save AlexDoanTB/c6665bc58c076a1a76082961bc575f3a to your computer and use it in GitHub Desktop.
ThingsBoard vidoe tutorials: Examples of configuration of Hierarchy widget
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Configuration code for HTML widget// | |
| <div class='card'> | |
| <div class='content'> | |
| <div class='column'> | |
| <h1>Current entity</h1> | |
| <div class='value'> | |
| ${entityName} | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| //To make your nodes in hierarchy coloured (red)// | |
| var entity = nodeCtx.entity; | |
| var text = entity.name; | |
| var data = nodeCtx.data; | |
| if (data.hasOwnProperty('hasAlarm') && data['hasAlarm'] !== null && data['hasAlarm'] === 'true') { | |
| text = "<font color=\"red\">" + text + "</font>"; | |
| } | |
| //To add some text (exclamations for example) to nodes appearance// | |
| var entity = nodeCtx.entity; | |
| var text = entity.name; | |
| var data = nodeCtx.data; | |
| if (data.hasOwnProperty('hasAlarm') && data['hasAlarm'] !== null && data['hasAlarm'] === 'true') { | |
| text = "<b> !!!</b>"; | |
| } | |
| //To change icon of particular node. You may choose any pic from MaterialIcons set or input URL to image file// | |
| var data = nodeCtx.data; | |
| if (data.hasOwnProperty('hasAlarm') && data['hasAlarm'] !== null && data['hasAlarm'] === 'true ') { | |
| return {materialIcon: 'settings_remote'}; | |
| } else { | |
| return 'default'; | |
| } | |
| //Disabling makes your node inactive in hierarchy// | |
| var data = nodeCtx.data; | |
| if (data.hasOwnProperty('nodeDisabled') && data['nodeDisabled'] !== null) { | |
| return data['nodeDisabled'] === 'true'; | |
| } else { | |
| return false; | |
| } | |
Author
Hey Alex - can we use entity "Description" field to change the text? Trying to use additionalInfo, but not working. Thanks!
What text do you mean? Entity description field is not accessible for and from widgets. It is just an internal note
Hi, Alex
I want the sort function to be able to sort based on the widget data.
But I used console.log to print the received data, and found that besides entity and name, the data of nodeCtx1 and nodeCtx2 are often empty. Unlike text functions or other functions that often fetch data.
May I ask what settings do I need to make for the hierarchy widget so that the data can be obtained normally in the sort function?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Alex - can we use entity "Description" field to change the text? Trying to use additionalInfo, but not working. Thanks!