Okay, this is a problem I have been spending way too long trying to solve, let alone elegantly.
Overview:
-
Data Structure: We have 2 arrays of data (segment 1 and segment 2) in which we display one of these arrays conditionally. Each array has multiple levels of nested data with the following structure:
[ { "SEGMENT_ID": 2, // ...other keys / values "portfolios": [ { "PORTFOLIO_ID": 5, // ...other keys / values "clusters": [ { "CLUSTER_ID": 26, // ...other keys / values "groups": [ { "OPERATION_GROUP_NUMBER": "XXXXX", // ...other keys / values "entities": [ "XXXXX", "XXXXX" ], "xData": [ "Feb-25", "Jan-25" ], "yData": [] }, { "OPERATION_GROUP_NUMBER": "XXXXX", // ...other keys / values "entities": [ "XXXXX", "XXXXX", "XXXXX", "XXXXX" ], "xData": [ "Feb-25", "Jan-25" ], "yData": [] } ] } ] } ] } ]
-
HTML Structure: In our transformer, we loop through this data to create the HTML for our HTML component. Below is the section of our HTML where we attempt to invoke an action that will get the ID of the clicked HTML element:
<div class="button" data-click-target="${group?.OPERATION_GROUP_NUMBER}" data-id="${group?.OPERATION_GROUP_NUMBER}">…</div>
-
Goal: We want to be able to target this
data-click-target
ordata-id
attribute on the above div element so we can pass it as a variable that stores theOPERATION_GROUP_NUMBER
that was clicked, but you cannot set data within a transformer, only a query. I have been struggling on exactly how to capture that ID from our HTML element within our HTML template so we can use that ID to display more granular metrics about that specific operation group.
We had to build this as a custom HTML component as the table component offered by retool has some shortcomings when it comes to properly displaying aggregated metrics for this complex data, which is a table we built that has collapsible rows for each level (segment level > portfolio/market level > cluster level > operation group level).
Does anyone have any insight on the best way to go about this when working with nested for / of loops of complex data from an HTML element from within an HTML component?
I'm also happy to provide any other details like code snippets, etc. for further clarity. I just didn't want to post a long slew of code unless prompted as it is a lot to look at.
Any information would be appreciated from anyone who's had to configure data for a similar situation! Thank you in advance, retool community!