cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Table - containing sap.m.Select - bind data

Former Member
0 Kudos

Hi,

I have a dynamic table I am building using JS. One of the columns is based on the sap.m.Select object.

For this column I am able to bind it to a JSON array to define the available options. The issue I have is how to bind the sap.m.Select to the overall table binding, so that I can get the chosen option.

The JSON array is defined as


var trafficLights = {

    "options": [

        {

            "Key": "",

            "Value": "Please Select..."

        },

    {

            "Key": "Red",

            "Value": "Red"

        }   

    ]};

Below is the code to define the sap.m.Select column


var selectField=new sap.m.Select(id);

var oModel = new sap.ui.model.json.JSONModel();

oModel.setData(trafficLights.options);

selectField.setModel(oModel);

var itemTemplate = new sap.ui.core.ListItem();

itemTemplate.bindProperty('key', 'Key');

itemTemplate.bindProperty('text', 'Value');

selectField.bindItems('/', itemTemplate);

I then add this object to the table via


var oColumn = new sap.ui.table.Column({

    label: new sap.ui.commons.Label({

         text: jsonObject.tableDefinition[i].columnHeader,                                }),                               

    template: selectField,                           

});

Initially the table is empty, so upon adding a new row, I "push" a JSON object to an array and then bind that array to the table, thus adding a blank row to the table.

Upon clicking an accept button, I need to get the content of the table back into my JSON object. I use the following to get the table content: -


sap.ui.getCore().byId("dynamicDataTable").getModel().getData()

This the result does not contain what drop down value was chosen.

Thanks

Martin

View Entire Topic
karthikarjun
Active Contributor
0 Kudos

sap.ui.getCore().byId("dynamicDataTable").getModel().getData()   - This is where you can use the table selection and you should make sure that you follow 'Select' class model.

Will this help? JS Bin - Collaborative JavaScript Debugging

Regards,

Karthik A