In a List, bind selected record, or add custom handler on selectionchange

Hi Community!

 

How can I bind the selected row of a list to a property in the ViewModel, or even how can I execute custom code (custom handler) when the row is changed?

Thanks advance!
Ignacio

Like 0

Like

1 comments
Best reply

Hi,

 

Here is a simple code with an example of how to retrieve selected records:

{
            request: "crt.HandleViewModelAttributeChangeRequest",
            handler: async (request, next) =>  {
              if (request.attributeName === 'GridDetail_9ib3s20_SelectionState') {
                const gridDetailSelectionState = await request.$context.GridDetail_9ib3s20_SelectionState;
                if (gridDetailSelectionState) {
                   let selectedRows = await request.$context.GridDetail_9ib3s20_SelectedRows || []
;
                  console.log(selectedRows);
                }
              }
              return next?.handle(request);
            }
          }

It's triggered when the record is selected in the list and retrieves all selected rows in the list. If you need to retrive currently selected record you may add the following line

 

const lastRowSelected = request.$context.GridDetail_9ib3s20_ActiveRow;

 

Also don't forget to change GridDetail_9ib3s20 to your list.

Hi,

 

Here is a simple code with an example of how to retrieve selected records:

{
            request: "crt.HandleViewModelAttributeChangeRequest",
            handler: async (request, next) =>  {
              if (request.attributeName === 'GridDetail_9ib3s20_SelectionState') {
                const gridDetailSelectionState = await request.$context.GridDetail_9ib3s20_SelectionState;
                if (gridDetailSelectionState) {
                   let selectedRows = await request.$context.GridDetail_9ib3s20_SelectedRows || []
;
                  console.log(selectedRows);
                }
              }
              return next?.handle(request);
            }
          }

It's triggered when the record is selected in the list and retrieves all selected rows in the list. If you need to retrive currently selected record you may add the following line

 

const lastRowSelected = request.$context.GridDetail_9ib3s20_ActiveRow;

 

Also don't forget to change GridDetail_9ib3s20 to your list.

Show all comments