[OutSystems Data Grid] Looking for a FOR EACH example that uses GetSelectedRowsData and pulls out data
data-grid-reactive
Reactive icon
Forge component by Platform Maintenance
Service Studio Version
11.53.9 (Build 61018)

I am accessing GetSelectedRows, from the reactive data grid - OutSystems DataGrid, and I want to pull out a value from a row in GetSelectedRowsData.  A For Each loop appears to be the correct solution, but I am not finding a way to access a single row from GetSelectedRowsData.  Once I get the row "out" then I can JSONDeserialize it and access the data.  The problem is getting a row "out" of the list from GetSelectedRowsData and I want to loop through this.

Thank you.

mvp_badge
MVP

Hi Bryan,

I assume you are using the Reactive component? I can't find GetSelectedRows, only GetSelectedRowsData? Is that the one you are using?

Yes on both accounts.

I edited my "question" to correct my error.


My issue could also be solved if I can get the JSONDeserialize.JSONString that will get me a row from GetSelectedRowsData.  Like shown in this example (which I copied from another issue).  


I have downloaded the .OML file from said example https://www.outsystems.com/forums/discussion/72829/how-to-duplicate-data-grid-reactive-rows/ and it is the same string I am using - which does not work.  If anyone has a working one, I would greatly appreciate it.


mvp_badge
MVP

I've not used DataGrid that much, but it seems that GetSelectedRowsData outputs a List (RowsData) of a RowData structure, that has a DataItem and a RowIndex attribute. DataItem has "Data source serialized to string" as description, isn't it the JSON you are looking for?

You would think, however I cannot access the information contained there in.  The only thing I have been able to make work is using GetSelectedRowsData .Current.RowIndex to feed into GetRowData to get a string I can JSONDeserialize.  GetSelectedRowsData .Current.DataItem (even if I have exactly 1 row in it) does not work.  

Hence my thought for a For Each loop, because it steps through each item in the list.  GetSelectedRowsData returns a list of rows.  Seemed like for each should get me to a single row, no dice.  I dislike ignoring the data I have in hand and then using a 2nd API call to get the data I already have.  

Hope this is clearing up my issue.

mvp_badge
MVP

Hi Bryan,

Based on my observation and a little bit of research, I got to the conclusion that the GetSelectedRowsData client action only retrieves the selected rows (free mouse selection) irrespective of the checkbox selection. i.e. The GetSelectedRowsData action doesn't have any association with the CheckboxColumn selection.

Refer to this post for solution: select-rows-with-checkbox-and-bulk-select

or else refer to the attached oml.

Demo screen: DataGrid_GetSelectedRowsData


I hope this helps you!


Kind regards,

Benjith Sam

RWA_Lab_DataGrid_GetSelectedRowsData.oml

I do not know what question you are answering, it is not the question that I asked.  Your links were not relevant to my problem.  You .OML file did not seem to load properly.  

mvp_badge
MVP

Hi Bryan,

I'm sorry, I misunderstood and over assumed your explanation. I think now I understand your point. As Dorine already mentioned the GetSelectedRowsData client action is returning the row DataItem as an array of objects. To get the row data i.e. object in Array 0 index, you can use the below-mentioned JS code.

JS Snippet:

var arrayObj = JSON.parse($parameters.JsonObjArray);
arrayObj = arrayObj[0];
$parameters.JsonObj = JSON.stringify(arrayObj);

Demo screen: DG_GetSelectedRowsData

Refer to the attached oml file.


I hope this helps you!


Kind regards,

Benjith Sam

RWA_Lab_Task_DG_GetSelectedRowsData.oml

Hi Brian,

for some reason, there is a set of extra square brackets around the JSON items in the

GetSelectedRowsData.RowsData list.  Maybe there is a reason for this, or maybe it's a querkyness of that api.

See attached oml, if you deserialise it to a list of your entity instead of a single item of your entity, you can extract the information.

Dorine  

QDR_RowData.oml

EDIT : I just saw your comment on another post (original data last year) that the deserialize isn't working, this makes me think that these extra square brackets are a recent change and maybe a bug... 

Dorine,

I assumed that the [ ] brackets denoted that it was a list, in any event I agree that they seem to be the issue.  I am digesting your solution now and I think I get it all - unfortunately it will not run in my personal dev environment via OutSystems.  I might have a few more questions for you.  

Thank you.

Sure,

what is the issue with it running ?  Not able to install ?


Foreign Module Error

Your OutSystems subscription only allows uploading modules developed in your environment, or downloaded from the OutSystems Forge. To share this module with the community, upload it at http://www.outsystems.com/goto/forge.


No idea. LOL

You gave me just what I needed.  Once I set the datatype of the JSONDeserialize to a LIST of myDataType.  I was able to read right from GetSelectedRowsData and assign data elements to local variables.  

Thank you!  

mvp_badge
MVP

This looks like a bug in the API though, be sure to open a Support Case with OutSystems!

Hi @Dorine Boudry 

We'll try to take a look at this and try to understand if something changed in the meantime.
Which version are you using? The reason for those brackets is because when we are about to serialize the data the code it putting it always put as an array.

Besides this, and just to have the whole information, despite this everything is working as expected right?
Once we can tackle this I'll provide some follow-up on this topic.

Best Regards,
GM

Hi @Gonçalo Martins ,

I don't know if everything is working as expected 😄

All I did was try to understand why Bryan couldn't deserialize the json coming out of the GetSelectedRowsData action.  And the reason is those extra [].

I think, functionally, it is not correct to return a JSON list instead of a JSON object in that spot.  

But I don't know the reason, in which use cases would this actually be a list??

Dorine 

Hello,

Once I walked though Dorine's solution and I realized that I needed to set the datatype of the Deserialize to "mydatatype List", then things worked as expected in the flow.  

I did have the unexpected experience that using GetSelectedRowsData only works when I click on the RowNumber Column of my grid.  Clicking anywhere on a row selects it, but GetSelectedRowsData is empty unless I clicked on the RowNumber cell for my row.  This seems an odd behavior to me.

Hello @Dorine Boudry 

We finally got bandwidth to take a look at this and it was actually a side-effect on another API introduced more than 1year ago and it will be fixed under the code ROU-3646.

Best Regards,
GM

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