1
votes

This may be a basic question, but it's my first, so please be kind :-).

I have a sap.m.table with two models, one model with transaction data (trxModel) and another model that is used to display a sap.m.select list (reasonCodeModel). The table model is set to trxModel.

The selected value key from the dropdown needs to update a value (ReasonCodeID) in the trxModel when a value from the reason code list is selected.

I can retrieve the selected key in the change event as so

var selKey = evt.getParameter("selectedItem").getKey();

Is there a simple way to find the trxModel relevant model path from the table row Select list value I've just modified? Or is it possible to bind the ReasonCodeID from the trxModel to the ReasonCodeID field in the reasonCodeModel?

Just an extra piece of info, The current row is selected and is accessible

var selItem = dtlTable.getSelectedItem();

2nd question and I guess could be kind of related, is there a way of getting the table model path based on the selected item (highlighted row) of the table? And vice a versa?

More details on Select & Table binding.

                    var tabTemplate = new sap.m.ColumnListItem(
                            {
                            ::

                                new sap.m.Select(
                                        "idReasonCodeSelect",
                                                {
                                                    enabled : false,

                                                    change : function(evt) {
oS4View.getController().changeReasonCodeSel(evt);
                                                        }
                                                    }
                                            ),

Bind the resource code Select to the Table

                    // bind the reason codes to the reason code model
                    sap.ui.getCore().byId("idReasonCodeSelect").setModel(
                            oReasonCodeModel);

                    sap.ui.getCore().byId("idReasonCodeSelect").bindAggregation("items", "/results",
                                            new sap.ui.core.Item({
                                                key : "{ReasCodeID}",
                                                text : "{ReasCodeDesc}"
                                            }));

Per Qualiture comment, how do I bind the Select key to the table model ReasonCodeID value?

1

1 Answers

0
votes

I found an approach to tackle the first part of my question above

From the change function on the Select, I can find the path of the table model using the following.

var path = evt.getSource().getParent().getBindingContext().sPath;

2nd Update: On the selectionChange event on the table, there's a couple of options to find the associated model path or model content.

// find the model path
oModelPath = selItem.getBindingContext().getPath();

// model values 
oItem = oEvent.getParameter("listItem").getBindingContext().getObject();

So my only remaining issue, While I loop through the table model results (trxModel) and I want the Select List (using setSelectedKey) to reflect the ReasonCodeID value in the trxModel.