Skip to content

Instantly share code, notes, and snippets.

@gbrault
Created December 4, 2016 12:04
Show Gist options
  • Save gbrault/6feb5a204649ed60036f81137e8b973e to your computer and use it in GitHub Desktop.
Save gbrault/6feb5a204649ed60036f81137e8b973e to your computer and use it in GitHub Desktop.
Node-Red dynamic Table template
<table>
<tr>
<th ng-repeat="(key,value) in table[0]">{{key}}</th>
</tr>
<tbody ng-repeat="row in table">
<tr ng-if="$even">
<td ng-repeat="(key,value) in row">{{value}}</td>
</tr>
<tr ng-if="$odd">
<td style="background-color:#f1f1f1" ng-repeat="(key,value) in row">{{value}}</td>
</tr>
</tbody>
</table>
<style>
table, td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
</style>
<script>
(function(scope) {
debugger;
scope.table=[];
scope.$watch('msg', function (newValue, oldValue, scope) {
scope.table=JSON.parse(scope.msg.payload)[0];
});
})(scope);
</script>
Copy link

ghost commented Oct 14, 2018

It displays nothing

@PRO2XY
Copy link

PRO2XY commented Nov 18, 2018

How do you feed the payload? Formatted to a JSON object, or string, or array or what?

@alexmed
Copy link

alexmed commented Dec 11, 2020

How do you feed the payload? Formatted to a JSON object, or string, or array or what?

i found it to be feeded as a string JSON formatted payload (because template parses it into an object as we can see there from JS code)

so msg.payload to be like this

[[{"displayed as a table name":"displayed in a first data row"},{"key1":"value1 goes in second data row"},{"key2":"value2 in third data row"}]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment