cancel
Showing results for 
Search instead for 
Did you mean: 

fetching the index of a row on basis of radio button selection

former_member200679
Participant
0 Kudos

Hi,

i am using a sap m table with mode as singleselect. Below is the screenshot of table:

and here is the code used for displaying the above table in xml :

<l:Grid defaultSpan="L12 M12 S12" id="redforscan">

<l:content>

<Table id="S1Table2" growing="true" growingScrollToLoad="true"

layout="ResponsiveGridLayout" inset="false" width="100%" mode="SingleSelectLeft">

<columns id="S1Table2_columns">

<Column id="S1Table2_col1" minScreenWidth="Tablet" hAlign="Left"

demandPopin="true">

<header id="S1Table2_col1_header">

<Text id="S1Table2_col1_label" text="{i18n>S1tab2col1Text}" />

</header>

  </Column>

<Column id="S1Table2_col2" minScreenWidth="Tablet"

demandPopin="true">

<header id="S1Table2_col2_header">

<Text id="S1Table2_col2_label" text="{i18n>S1tab2col2Text}" />

</header>

</Column>

<Column id="S1Table2_col3" minScreenWidth="Tablet" width="11em"

hAlign="Center" demandPopin="true">

<header id="S1Table2_col3_header">

<Text id="S1Table2_col3_label" text="{i18n>S1tab2col3Text}" />

</header>

</Column>

<Column id="S1Table2_col4" minScreenWidth="Tablet" hAlign="Center"

demandPopin="true">

<header id="S1Table2_col4_header">

<Text id="S1Table2_col4_label" text="{i18n>S1tab2col4Text}" />

</header>

</Column>

<Column id="S1Table2_col5" minScreenWidth="Tablet" hAlign="Center"

demandPopin="true">

<header id="S1Table2_col5_header">

<Text id="S1Table2_col5_label" text="{i18n>S1tab2col5Text}" />

</header>

</Column>

<Column id="S1Table2_col6" minScreenWidth="Tablet" hAlign="Center"

demandPopin="true">

<header id="S1Table2_col6_header">

<Text id="S1Table2_col6_label" text="{i18n>S1tab2col6Text}" />

</header>

</Column>

<Column id="S1Table2_col7" minScreenWidth="Tablet" hAlign="Center"

demandPopin="true">

<header id="S1Table2_col7_header">

<Text id="S1Table2_col7_label" text="{i18n>S1tab2col7Text}" />

</header>

</Column>

</columns>

</Table>

</l:content>

</l:Grid>


I am not able to get the index of the selected row as i need to navigate to next view depending on the index of current views table.


Please suggest a way to get the index of selected row as soon as possible.



Thanks,



Saurabh.

Accepted Solutions (1)

Accepted Solutions (1)

former_member200679
Participant

Thanks everyone for your inputs. I found the answer on this link itself : . This works fine for getting the index of a radiobutton of table whose mode is singleselect.

Answers (3)

Answers (3)

saivellanki
Active Contributor
0 Kudos

Hi Saurabh,

Use selectionChange event handler for table, something like this:


<Table id="S1Table2" growing="true" growingScrollToLoad="true"

layout="ResponsiveGridLayout" inset="false" width="100%"

mode="SingleSelectLeft"

selectionChange="onSelectionChange">

And in the onSelectionChange event, try like this:


onSelectionChange: function(oEvent){

var oSelectedItem = oEvent.getParameter("listItem");          //Get Hold of SelectedItem

var oTable = oEvent.getSource();                                             //Get Hold of Table

oTable.indexOfItem(oSelectedItem);                                        //Get the index of Selected Item

}             

Regards,

Sai Vellanki.

Former Member
0 Kudos

Hi Saurabh,

There are many ways but i think you can use below snippet:

<Table id="S1Table2" growing="true" growingScrollToLoad="true" select="onSelect"

layout="ResponsiveGridLayout" inset="false" width="500px" mode="SingleSelectLeft">

onSelect: function (oEvent) {

       var oSelected = oEvent.oSource.getSelectedItem();

    var oItems = oEvent.oSource.getItems();

    for(var i=0;i< oItems.length;i++)

    {

  if( oItems[i] === oSelected)

  {

  alert(i);

  }

    }

    }

Regards

Naveen S

former_member182862
Active Contributor
0 Kudos

can u please share your code for select handler?