Skip to content

Instantly share code, notes, and snippets.

@AlexDoanTB
Last active March 9, 2023 04:04
Show Gist options
  • Select an option

  • Save AlexDoanTB/c6665bc58c076a1a76082961bc575f3a to your computer and use it in GitHub Desktop.

Select an option

Save AlexDoanTB/c6665bc58c076a1a76082961bc575f3a to your computer and use it in GitHub Desktop.
ThingsBoard vidoe tutorials: Examples of configuration of Hierarchy widget
//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;
}
@LeslieWong2021
Copy link

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