Created
December 4, 2016 12:04
-
-
Save gbrault/6feb5a204649ed60036f81137e8b973e to your computer and use it in GitHub Desktop.
Node-Red dynamic Table template
This file contains 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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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"}]]