Hello All,
How to Deselect the Selected rows from Grid with Action button.
Regards,
Vinod
Hello @Vinod Kumar R
In order to achieve this use case you can create a Javascript node with the following code that you can call on demand:
//Function to implement the 'deselect all' function deselectAll(gridId, rowNumbers){ let grid = OutSystems.GridAPI.GridManager.GetGridById(gridId); let rowNumberList = JSON.parse(rowNumbers); if (grid.features.rowHeader.hasCheckbox) { rowNumberList.forEach((index) => { grid.features.selection.getMetadata(index).isChecked = false; grid.provider.rows[index].isSelected = false; }); grid.provider.collectionView.refresh(); } else { rowNumberList.forEach((index) => { grid.provider.rows[index].isSelected = false; }); } } //Gets the Grid Instance by the Grid block Id let grid = OutSystems.GridAPI.GridManager.GetGridById($parameters.GridId); let numRows = new Array(); //iterate over all rows to check which are selected grid.provider.rows.forEach ( function(r) { if(r.isSelected) { numRows.push(r.index); } }); //If we have rows selected call the function if(numRows.length > 0){ deselectAll($parameters.GridId,JSON.stringify(numRows)); }
Hope it helps!
Cheers,GM
Thanks @Gonçalo Martins .
It worked.
Hi @Gonçalo Martins,
This JS is not working when used in Grid's OnCellClick Event. I want to Deselect the row which is selected already, in one of the grid events, OnCellClick event.
When I click on any cell on the grid, then the OnCellClick event fires and in that event, I want to deselect the clicked row which is already selected.
Please help...
Hi!
The "isSelected" parameter set to False deselects the rows in the "RowsNumbers"
No, not straightforward, but is in the parameter description:
"Set to False to unselect the given rows list."
Hope this helps
Graça
Thanks for your response Maria,
I tried SetRowAsSelected, but it didn't work.
Well @Gonçalo Martins, I couldn't get the javascript solution to work; I could see that it had the gridId parameter okay, but still it couldn't get a handle on OutSystems.GridAPI.GridManager using that. Maybe those things have changed since then? I'm using 'OutSystemsDataGrid' Version 2.6.3.
Or are there prerequisites that are implied but not explicitly stated for that script?
In my own scenario, underlying data had been deleted and the data action was refreshed, but now the same grid rows were still selected, though different records were in their place. My concern was that the user might then sloppy-click a "remove records" button, mindlessly click-through the "are you sure?" warning, and inadvertently delete data that they didn't mean to delete. My solution was instead to use "RemoveSelectedRows" just after the actual deleting and just before refreshing the data action.