102
Views
5
Comments
Solved
[OutSystems Data Grid] SetRowAsSelected doesn't work with RowCheckbox as RowHeader
outsystems-data-grid
Reactive icon
Forge asset by OutSystems
Application Type
Reactive

Hey everyone

I'm trying to select rows programatically with the use of the new feature in the latest release of the Datagrid Component.
But the main functionallity that should come with the feature is actually disabled. This doesn't make much sense right? 

2022-07-19 16-56-14
Giuliana Silva
Staff
Solution

Hi @AndreRocha,

Thank you for your report. We've created a task in our backlog to investigate and add this use case. Refer to the code ROU-4320 in future release notes.

As a workaround you can use some custom code to cover this case:

  1. Create a new ClientAction with these input parameters:
    • GridId: Text type
    • RowNumbers: Integer List type
    • isSelected: Boolean type
  2. Add JSONSerialize and assign to the Data property, the RowNumber input parameter
  3. Add a JavaScriptNode with these input parameters:
    • GridId: Text type
    • RowNumbers: Text type
    • isSelected: Boolean type
  4. In the JavaScriptNode enter the code:

    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;

        });

    }


Now you can use this Client Action the same way you would use the SetRowAsSelected.

I've attached an OML file with this fix implemented for better understanding.


Hope it helps,

Giuliana.




SetRowCheckboxAsSelected.oml
2022-09-29 13-59-54
AndreRocha

It worked as expected! Thank you so much!

2022-07-19 16-56-14
Giuliana Silva
Staff

Hi, @AndreRocha!

Just a correction on the code above, in the else statement it should be rowNumberList instead of rowsIndex:

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 {

        rowNumberList.forEach((index) => {

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

        });

    }


Regards, 

Giuliana.

2022-09-29 13-59-54
AndreRocha

Hey @Giuliana Silva 

I had to modify the code a bit either way for my use case, but everything worked out in the end.


Thank you very much again

UserImage.jpg
Reshma Naz

Hi,

FYI, For anyone facing issue for the first record using above, please change the property "Serialize default values" of the JSON Serialize widget to Yes as for first row it is 0.

Thanks,

Reshma

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