[OutSystems Data Grid] Outsystems React DataGrid : How to extract value (id, etc) from Action Column event ?
data-grid-reactive
Reactive icon
Forge component by Platform Maintenance

There's got to be a better way to do this : in the Outsystems React DataGrid, when handling the event from a Action Column, we get the "Line" value, a JSONed version of the current record, and then use JSONDeserialize to feed the "Line" value into a structure or Entity. 

Now here's the kicker : how do you do that when the data source has 10 joins in it ? What if we change add or remove columns from the data source, the target structure won't work anymore... 

Is there a simple way to get a single value from the row ?


Hello Francois,

I have come up with a slightly different approach than regex, very robust, but it needs some care/best practices to be adhered to by all developers.

it goes like this :

1) in all your aggregates / sql widgets that retrieve data for a datagrid, you add a calculated column with an agreed upon name, that holds the id that you are interested in.  (this is the most fragile part, it has to be the correct id, and it has to be the correct name)  Once this is set up correctly, it will not break until the changes to your aggregate involve that id column.

2) You create a reusable client action (as a function if you like) that does a json deserialize to a record structure with as only attribute a longinteger with that same name

3) wherever you need the id of a clicked datagrid row, just call that function feeding it the clicked line, et voila

See attached oml for an example

Dorine


QDR_DatagridRowInfo.oml

Hey Francois,


What do you mean by a single value from the row?

Hi Gabriel

For instance, in a products grid, from the click in an action column, we want to open a details page of the item: we need to pass the Id of the selected item to the details page. 

Other than copying the "Line" JSON payload into a matching structure/Entity, I've not found (yet) a way to simply extract the ID value from the Line...

The current approach is to run it in debug, grab a copy of the JSON Line parameter in the action column event handler and create a matching structure with that. This works, but when someone decides to change the source data (add/remove a join, etc.) then the structure won't match and everything will break. 

Ideally, having a JSON XPath type action would let us extract the required field value without the hassle and fragility of deserializing into a rigid, set structure. 

Hello Francois,

I have come up with a slightly different approach than regex, very robust, but it needs some care/best practices to be adhered to by all developers.

it goes like this :

1) in all your aggregates / sql widgets that retrieve data for a datagrid, you add a calculated column with an agreed upon name, that holds the id that you are interested in.  (this is the most fragile part, it has to be the correct id, and it has to be the correct name)  Once this is set up correctly, it will not break until the changes to your aggregate involve that id column.

2) You create a reusable client action (as a function if you like) that does a json deserialize to a record structure with as only attribute a longinteger with that same name

3) wherever you need the id of a clicked datagrid row, just call that function feeding it the clicked line, et voila

See attached oml for an example

Dorine


QDR_DatagridRowInfo.oml

Hello Dorine, 

Thanks for the solution and clear instructions! 

I just tried a proof-of-concept version of your approach using a JSONDeserialize -> Record.RowId straigth in the event handler, and it works nicely. Marking your answer as solution.

We also found two other ways : 

1. using ardoJSON from the Forge, we can input the JSON Line + Path and output any field value

2. using a Javascript action, we can parse the Line into a JSON object and then get the field value

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.