cancel
Showing results for 
Search instead for 
Did you mean: 

MultiSelect Table - how to know which was the current item clicked/selected

former_member260921
Participant
0 Kudos

Hi,

I have a MultiSelect table.

<Table id="idProductsTable" inset="false" mode="MultiSelect" selectionChange="onInvoiceSelectionChange" items="{ path: '/value', sorter: { path: 'DocNum' } }">

When an item is selected (or un-selected) the event triggers a function:

onInvoiceSelectionChange : function(oEvent) {...

I need to know which item was selected so I coded this.

var oCtx = oEvent.getSource().getSelectedItem().getBindingContext();
var path = oCtx.getPath();

This always returns the first (lowest) selected item in the list - not the current one: E.g. if paths are:

/value/0

/value/1

/value/2

If I select/click the first item and then the second item the path = "/value/0" BOTH TIMES!

I need to determine "/value/1" was the selection the second time.

There does not seem to be any property "current item clicked" in the oEvent or its child objects. Just the list of selected items with the "lowest" always returned as the path.

Thanks for any help.

Regards,

Mel

Accepted Solutions (1)

Accepted Solutions (1)

former_member365727
Active Contributor
0 Kudos

in selection change event handler write the below code

onInvoiceSelectionChange: function(oEvent){
   var oSelectedItem = oEvent.getParameter("listItem");   //this gives currently selected/de-selected item
   var bSelected = oEvent.getParameter("selected");   //Boolean value - Indicates if the current item is selected or not

   var aSelectedItems = oEvent.getParameter("listItems");   //gives all the selected items
}
former_member260921
Participant
0 Kudos

Thank you, Srikanth

That worked.

Now I need to iterate through the list of items and check which are not selected. The aSelectedItems gives all the selected items. How to generate a list of all the items that are not selected? I will mark this question as answered and open a new one.

Thanks.

Regards,

Mel

former_member365727
Active Contributor
0 Kudos

loop through aSelectedItems and check if item is selected or not..

for(var in in aSelectedItems){
    if(aSelectedItems[i].getSelected()){
        //item is selected
    }else{
        //item not selected
    }
}

Answers (0)