cancel
Showing results for 
Search instead for 
Did you mean: 

Get sap.m.table row index depending on cell's search help selection

Former Member
0 Kudos

Hi,

I am using sap.m.table and have bound it to a template on edit button click. When user selects a specific cell, a search help ( manual entry is blocked) is opened [ values : A , B , C] and if he chooses "A", then value of cell changes to A on handleValueHelpClose function but I want to know the row of table that has been affected due to this value. Since it is a dynamic table, I know the cell id (oEvent.getSource().getId()) but how can I get the table row index ? Also I need to disable other columns of row if value is "A". What is the piece of code that can help me achieve this ?

Regards,

Janani

Accepted Solutions (1)

Accepted Solutions (1)

former_member227918
Active Contributor
0 Kudos

last char of id itself may be row index, that can be truncated out using substr(), if thats not helps,

you can also get the row index by its binding context path as below:

var sBindinPath = oEvent.getSource().getBindingContext().getPath();

var index = sBindinPath.substr(sBindinPath.length - 1);

And for disable/enable row can be achieved by one of the model property itself, as:

oModel.setProperty(sBindinPath + "/bEnabled", false) ;

and bind "bEnabled" to your desired column element like "<Input enabled="{bEnabled}" />

hope this help.

Former Member
0 Kudos

Hi Akhilesh,

Your solution should also do the trick but I haven't tried. Will reserve for future developments.

Thanks,

Janani

former_member227918
Active Contributor
0 Kudos

thats good issue has been resolved !:)

but above is recommended and good approach, your approach is not good one due to below points:

  1. cells in a global variable
  2. hard coding the index i.e. cells[2] ( in future if requirements change then you need to modify your code accordingly).

we should avoid these things if other good way is possible.

Former Member
0 Kudos

Hi Akhilesh,

I agree that your suggestion is the best approach of two in terms of best coding practice.

Regards,

Janani

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Akhilesh,

I tried a different route where I did not need sPath to be found and below is the step by step solution -

1. Define rowCells as global variable.

2. rowCells = this.getParent().getCells(); --> write it in valueHelpRequest function before you call fragment for select dialog

3. In function where confirm/close logic is written (eg. __handleValueHelpClose), validate value of selected item is "A" then disable column fields of that row like this - rowCells[2].setEnabled(false) -> means 3rd column of that row is disabled

Regards,

Janani