Skip to Content
0

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

Apr 20, 2017 at 04:38 AM

53

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Akhilesh Upadhyay Apr 20, 2017 at 06:32 AM
0

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.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Akhilesh,

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

Thanks,

Janani

0

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.

0

Hi Akhilesh,

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

Regards,

Janani

0
Janani Rajagopalan Apr 20, 2017 at 08:33 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded