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!
This my OML file, let's check it :D
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:
Ensure Row Identifier is Available: The SetRowAsSelected action requires a row identifier, which is typically the row's primary key or unique identifier.
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.
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:
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.
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.
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)
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:
Hi @Dhineshkumar B
you can use this JS to select the row you want:
Result:
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!
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.
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!
Let's do some combination, try this solution below, it works for me.
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!
Mine works ok with the code below:
Thank you! I implemented this method, and it’s working perfectly. I’m grateful for your assistance!
you're welcome :) I'm happy it helps.
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!
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.