Ui template // Send msg.topic from button click

Hy community,

im struggling long time now with this:
I want to do my own task/shopping list using node red and sqlite.
So far:

  • Sqlite works.
  • Feeding through dashboard works.
  • Doing select statemnts to show specific tagged tasks work.
  • Closing tasks in ui template does not work (see below).

In each column of a table there is a button. When clicked, the task with a specific id shall be set to "done".
But it doesnt work.. my html/javascript is not the best, Any suggestions?

ui template:

<h>{{msg.listshown}}</h>
<table style="width:100%">
  <tr>
    <th>id</th> 
    <th>task</th> 
    <th>duedate</th> 
    <th>status</th>
  </tr>
  <tr ng-repeat="x in msg.payload | limitTo:50">
    <td>{{msg.payload[$index].id}}</td>
    <td>{{msg.payload[$index].task}}</td>
    <td>{{msg.payload[$index].duedate}}</td> 
    <td> <button onclick="CloseTask()">done</button> </td>
  </tr>
</table>

<script>
function CloseTask() 
{
msg.topic="UPDATE rtm SET status = 'DONE' WHERE  id = '" + {{msg.payload[$index].id}} + "'";
return msg;
}
</script>

Try this (first make a copy of your existing ui_template)
change the ui_template to this

<h>{{msg.listshown}}</h>
<table style="width:100%">
  <tr>
    <th>id</th> 
    <th>task</th> 
    <th>duedate</th> 
    <th>status</th>
  </tr>
  <tr ng-repeat="x in msg.payload">
    <td>{{x.id}} </td>
    <td>{{x.task}} </td>
    <td>{{x.duedate}} </td> 
    <td> <md-button ng-click="send({payload:x.id})">
    done
        </md-button></td>
  </tr>
</table>

and un-click the Pass through messages from input. and `Add output messages to stored state.' options

This will return the id in msg payload and then you could use a template node to build the sql you need.

3 Likes

Thanks, Zenofmud! It works!

Thank you for your support, regards, node-n00b

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.