35
Views
3
Comments
Solved
[OutSystems Data Grid] [OutSystems Data Grid]How to get RowNumber when saving?
outsystems-data-grid
Reactive icon
Forge asset by OutSystems
Application Type
Reactive

Hi.

When Saving data, if there is any invalid data, I would like to inform the user of the corresponding row. Therefore, I would like to get the RowNumber, but I cannot get it with GetChangedLines. How can I do this?


Regards,

Haruka

2022-11-12 11-28-30
Gonçalo Martins
Staff
Solution

Hi @Haruka Arakawa 

You can add an event handler to manage and store or do whatever you need with the focused cell by using the following code in a JSNode in Grid’s OnInitialize event handler:

var myGrid = OutSystems.GridAPI.GridManager.GetGridById($parameters.GridWidgetId).provider;
	
myGrid.selectionChanged.addHandler(function (s, e) {
    // Get the selected cell's row index  
    var selectedRowIndex = myGrid.selection.row;
	
    // Use the rowNumber here with your logic
   console.log('Selected Row Index:', selectedRowIndex);
});


//where $parameters.GridWidgetId is the identifier of the Data Grid block

I hope it helps!

Cheers,
GM

2023-11-22 10-51-50
Jozy Sohail

Hi Haruka,

You can create a handler for OnCellValueChange, it will give you the row number.

Hope it helps,

Thanks

UserImage.jpg
Haruka Arakawa

Hi Jozy,

Thank you!

However, it looks like we can't use OnChange on a checkbox column, because our app grid needs to save all the rows that have changed, not just any row that has been checked.

Is there any other way, JavaScript or otherwise, besides OnChange, to get the number of the row where the change was made?

2022-11-12 11-28-30
Gonçalo Martins
Staff
Solution

Hi @Haruka Arakawa 

You can add an event handler to manage and store or do whatever you need with the focused cell by using the following code in a JSNode in Grid’s OnInitialize event handler:

var myGrid = OutSystems.GridAPI.GridManager.GetGridById($parameters.GridWidgetId).provider;
	
myGrid.selectionChanged.addHandler(function (s, e) {
    // Get the selected cell's row index  
    var selectedRowIndex = myGrid.selection.row;
	
    // Use the rowNumber here with your logic
   console.log('Selected Row Index:', selectedRowIndex);
});


//where $parameters.GridWidgetId is the identifier of the Data Grid block

I hope it helps!

Cheers,
GM

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