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>
@gbrault
Copy link
Author

gbrault commented Dec 4, 2016

add the code to a Node-Red dashboard template node adn feed with payload (see after) to display the first table
[[{"rowid":1,"IdCustomer":"ALFKI","CompanyName":"Alfreds Futterkiste","ContactName":"Maria Anders","ContactTitle":"Sales Representative","Address":"Obere Str. 57","City":"Berlin","Region":null,"PostalCode":"12209","Country":"Germany","Phone":"030-0074321","Fax":"030-0076545"},{"rowid":2,"IdCustomer":"ANATR","CompanyName":"Ana Trujillo Emparedados y helados","ContactName":"Ana Trujillo","ContactTitle":"Owner","Address":"Avda. de la Constitución 2222","City":"México D.F.","Region":null,"PostalCode":"05021","Country":"Mexico","Phone":"(5) 555-4729","Fax":"(5) 555-3745"},{"rowid":3,"IdCustomer":"ANTON","CompanyName":"Antonio Moreno Taquería","ContactName":"Antonio Moreno","ContactTitle":"Owner","Address":"Mataderos 2312","City":"México D.F.","Region":null,"PostalCode":"05023","Country":"Mexico","Phone":"(5) 555-3932","Fax":null},{"rowid":4,"IdCustomer":"AROUT","CompanyName":"Around the Horn","ContactName":"Thomas Hardy","ContactTitle":"Sales Representative","Address":"120 Hanover Sq.","City":"London","Region":null,"PostalCode":"WA1 1DP","Country":"UK","Phone":"(171) 555-7788","Fax":"(171) 555-6750"},{"rowid":5,"IdCustomer":"BERGS","CompanyName":"Berglunds snabbköp","ContactName":"Christina Berglund","ContactTitle":"Order Administrator","Address":"Berguvsvägen 8","City":"Luleå","Region":null,"PostalCode":"S-958 22","Country":"Sweden","Phone":"0921-12 34 65","Fax":"0921-12 34 67"}]]

@jprovan
Copy link

jprovan commented Aug 13, 2017

This displays nothing.

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