@5minds/node-red-dashboard-2-processcube-dynamic-table
Version:
A ui component for showing dynamic Data with actions in a table
51 lines (42 loc) • 1.57 kB
JavaScript
module.exports = function (RED) {
function UIDynamicTableNode(config) {
RED.nodes.createNode(this, config);
const node = this;
const group = RED.nodes.getNode(config.group);
const base = group.getBase();
//server-side event handlers
const evts = {
onAction: true,
beforeSend: function (msg) {
if (Array.isArray(msg)) return msg;
msg.payload = RED.util.evaluateNodeProperty(config.data, config.data_type, node, msg);
// Pass JSONata expressions to frontend for per-row evaluation
if (config.options && Array.isArray(config.options)) {
msg._jsonataLabels = {};
config.options.forEach((option, index) => {
if (option.label_type === 'jsonata' && option.label) {
msg._jsonataLabels[index] = option.label;
}
});
}
return msg;
},
onInput: function (msg, send, done) {
base.stores.data.save(base, node, msg);
},
};
if (group) {
group.register(node, config, evts);
} else {
node.error('No group configured');
}
}
RED.nodes.registerType('ui-dynamic-table', UIDynamicTableNode, {
defaults: {
outputs: { value: 1 },
},
outputs: function (config) {
return config.outputs || 1;
},
});
};