75
Views
13
Comments
Solved
[OutSystems Data Grid] Help with SetRowAsSelected in Grouping
outsystems-data-grid
Reactive icon
Forge asset by OutSystems
Application Type
Reactive

Hi everyone,

I’m trying to use the SetRowAsSelected action in a grouped data table, but it keeps failing.

I have set the maximum records to 100 per page, but I’m seeing 101 rows on the UI due to grouping.

Because of this, the SetRowAsSelected action is failing .


    let grid = OutSystems.GridAPI.GridManager.GetGridById($parameters.GridId)

    let rowNumberList = JSON.parse($parameters.RowNumbers)

    if (grid.features.rowHeader.hasCheckbox) {

        rowNumberList.forEach((index) => {

            grid.features.selection.getMetadata(index).isChecked = $parameters.isSelected;

        });

        grid.provider.collectionView.refresh();

    } else {

        rowsIndex.forEach((index) => {

            grid.provider.rows[index].isSelected = $parameters.isSelected;

        });

    }I’ve also tried using a script shared by @Giuliana Silva from the post 

https://www.outsystems.com/forums/discussion/88157/outsystems-data-grid-setrowasselected-doesnt-work-with-rowcheckbox-as-rowheade/

, but unfortunately, it didn’t work either for me.

I’m currently facing an issue and would greatly appreciate any suggestions or solutions you might have.

Thank you in advance for your help!

 

2025-12-04 09-01-03
Kiet Phan
Champion
Solution
SolutionConcept.oml
2024-09-17 12-24-07
Rammurthy Naidu Boddu
Champion

Hi @Dhineshkumar B

In OutSystems, the SetRowAsSelected client action in the Data Grid component can be used to programmatically select a row. When grouping is applied to the grid, selecting a row within a group works the same as in an ungrouped grid, but you need to ensure that the row is correctly referenced.

Here’s how you can handle SetRowAsSelected when grouping is applied:

Steps to Select a Row in a Grouped Data Grid:

  1. Ensure Row Identifier is Available: The SetRowAsSelected action requires a row identifier, which is typically the row's primary key or unique identifier.

  2. Get the Row's Index: Since the grid might be grouped, the row’s index can change based on the group structure. You can loop through the rows to find the correct one or extract it dynamically based on your grouping structure.

  3. Use the SetRowAsSelected Action: Once you identify the row, you can pass its identifier or index to the SetRowAsSelected action.

Example:

Here’s a sample implementation:

  1. Grouping the Grid: Ensure the Data Grid is grouped based on a certain column (like "Category" or "Region"). You can do this by configuring the grid’s grouping feature via its configuration options.

  2. Finding the Row in the Group: Write a logic to determine the row you want to select. If you are selecting based on a specific field, you might loop through the rows to find the correct one.

  3. SetRowAsSelected Usage: Use the SetRowAsSelected action, passing the row’s index or key. Example:

    outsystemsCopy codeDataGridActions.SetRowAsSelected(    GridId: "YourGridId",    RowIndex: YourRowIndex)

    If you are dealing with the row’s unique ID:

    outsystemsCopy codeDataGridActions.SetRowAsSelectedByKey(    GridId: "YourGridId",    Key: YourRowKey)

  4. Handling Grouped Rows: If your rows are grouped, make sure you adjust for the group's expansion. Ensure the group is expanded before setting a row as selected.

Notes:

  • Expanded Grouping: If a group is collapsed, you cannot select rows from it directly until the group is expanded. You might need to use an action to programmatically expand the group if needed.
  • SetRowAsSelectedByKey might be more reliable in scenarios where the grid is grouped, as row indexes can shift when groups are collapsed or expanded.
2025-12-04 09-01-03
Kiet Phan
Champion

Hi @Dhineshkumar B 

you can use this JS to select the row you want:

  1. let myGrid = OutSystems.GridAPI.GridManager.GetGridById("MyGrid").provider;
  2. var rowIndex = 3; // For example, row 3
  3. var rowHeaderCell = myGrid.rowHeaders.getCellElement(rowIndex, 1);
  4. var checkbox = rowHeaderCell.querySelector('input[type="checkbox"]');
  5. checkbox.click();

Result:


UserImage.jpg
Dhineshkumar B

Hi @Kiet Phan ,

Thank you for sharing the script. It works well in the console; however, I'm encountering an issue when I attempt to integrate it into my application dynamically by serializing the data and passing it to the script.

Specifically, I receive the error: "Cannot read properties of null (reading 'querySelector')." It seems that only the visible columns are being selected when using this script.

I used the script shared by @Giuliana Silva from the post ,

https://www.outsystems.com/forums/discussion/88157/outsystems-data-grid-setrowasselected-doesnt-work-with-rowcheckbox-as-rowheade/

which had a similar issue. When selecting all records, it works fine, but for separate row selections, it's not functioning correctly. However, once I scroll through all the records in the UI, the action works well. 

Could you provide any insights on how to resolve this issue? Additionally, if you could share the OML, it would be very helpful.

Thank you for your assistance!

2025-12-04 09-01-03
Kiet Phan
Champion

Hi @Dhineshkumar B ,

You're right, since the script is based on DOM, when item is hided, the script won't find it, so that it will returrn the error  "Cannot read properties of null (reading 'querySelector')." 

Incase you want the item get selected even when it is hided. Let my try something else. 

UserImage.jpg
Dhineshkumar B

Ok @Kiet Phan ,

If you find a solution to this issue or any way to address it, please let me know. I’d really appreciate your help. Thank you for your message! 


2025-12-04 09-01-03
Kiet Phan
Champion

Hi @Dhineshkumar B ,

Let's do some combination, try this solution below, it works for me.

  1. let myGrid = OutSystems.GridAPI.GridManager.GetGridById("MyGrid");
  2. var rowIndex = 3; // For example, row 3
  3. var rowHeaderCell = myGrid.provider.rowHeaders.getCellElement(rowIndex, 1);
  4. if (rowHeaderCell) {
  5.     var checkbox = rowHeaderCell.querySelector('input[type="checkbox"]');
  6.     checkbox.checked = true;
  7.     checkbox.dispatchEvent(new Event('change'));
  8. } else {
  9.     myGrid.features.selection.getMetadata(rowIndex).isChecked = true;
  10.     myGrid.provider.refresh();
  11. }


UserImage.jpg
Dhineshkumar B

Hi @Kiet Phan

While using this script, the single selection is functioning correctly; however, I am encountering issues with the dynamic selection.
Do you have any suggestions on how to work with the dynamic inputs? If possible, could you please send me the OML? 
Any guidance would be greatly appreciated.

Thank you!

2025-12-04 09-01-03
Kiet Phan
Champion

Mine works ok with the code below:

  1. let myGrid = OutSystems.GridAPI.GridManager.GetGridById("MyGrid");
  2. var rowindexes = JSON.parse("[1,3,4,7]");
  3. rowindexes.forEach(function(rowIndex) {
  4.     var rowHeaderCell = myGrid.provider.rowHeaders.getCellElement(rowIndex, 1);
  5.     if (rowHeaderCell) {
  6.         var checkbox = rowHeaderCell.querySelector('input[type="checkbox"]');
  7.         checkbox.click();
  8.     } else {
  9.         myGrid.features.selection.getMetadata(rowIndex).isChecked = true;
  10.         myGrid.provider.refresh();
  11.     }
  12. });

2025-12-04 09-01-03
Kiet Phan
Champion
Solution
SolutionConcept.oml
UserImage.jpg
Dhineshkumar B


Thank you! I implemented this method, and it’s working perfectly. I’m grateful for your assistance!

2025-12-04 09-01-03
Kiet Phan
Champion
UserImage.jpg
Dhineshkumar B



Hi @Kiet Phan , I'm having an issue with the script. I passed the parameters [0,1,2,4,5,6,7,8,9,10] (excluding 3), but it’s still selecting all records. Could you please take a look when you have a moment? Thanks! 

Screen Recording 2024-10-04 153752.mp4
2025-12-04 09-01-03
Kiet Phan
Champion

Hi @Dhineshkumar B,

You need to exclude the 0 from your index list. Because the 0 is parent. When you check the parent, all the childrend will be checked.

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