Skip to Content

Set selectedKey of sap.m.Select (drop down) in sap.m.Table dynamically

Hi All,

I have such a problem - sap.m.Select (drop down) is a column of sap.m.Table and I am not able to set property selectedKey dynamically. The reason why I need this - because it might have different preselected values per table row. I will try to illustrate the problem with some coding:

aCells[n] = new sap.m.Select({ //aCells[n] is an array of table columns, part of table row template

Drop down:

selectedKey : "{rowDropdown}", //<---only hard code values work here

items : { path : "/",

template : oItemTemplate,

templateShareable: true }

}).setModel(oModel);

Table:

var oTable = new sap.m.Table({

fixedLayout : false,

columns : aHeader, //<---array of new sap.m.Column()

items: { path : "/",

template : oTemplate,

templateShareable: true } }).setModel(oModelRows);

Every other table column receives different values per row correctly, using the same approch: variables like "{rowCheckbox}", "{rowText}", "{rowDate}", and so on, but this does not work with drop down, I guess because drop down gets a separate model in step before for populating it's values, perhaps that 's why drop down then ignores the variable "{rowDropdown}".

Any ideas how to deal with such issue?

Thanks,

Regards,

Mindaugas

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Best Answer
    Apr 20 at 08:44 PM

    Hi All,

    I am closing this thread, because I made it working this way:

    1. creating one bing model for a table, which also contains data for each dropdown, means we have an array per row for each dropdown

    2. bind the array mentioned in step 1 to a dropdown, for exmple this way:

    var templVar = "rowDropdown"; //in my case it's a variable, in this example a constant

    var templVarAll = "rowDropdownAll"; //in my case it's a variable, in this example a constant

    var oItemTemplate = new sap.ui.core.Item({

    key : "{key}",

    text : "{text}" });

    var oObject = new sap.m.Select({

    selectedKey : "{"+templVar+"}",

    items : {

    path : templVarAll, //***no curly brackets round a variable here***

    template : oItemTemplate,

    templateShareable: true } });

    3. set model mentioned in step 1 to a table

    There is no need to give a name to a model, because just 1 model is used anyway.

    If someone gets in similar problems and needs more details, let me know please.

    Thanks,

    Regards,

    Mindaugas

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 08 at 06:36 PM

    Hi Dennis,

    not really... with these templates "{rowCheckbox}", "{rowText}", "{rowDate}" I am populating table rows with some values in a loop, in fact all work fine without a slash symbol, just a drop down does not work.

    Regards,

    Mindaugas

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 08 at 08:19 PM

    Try below

    {JSONModelName>rowDropdown}

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 19 at 08:31 PM

    Hi Abdul,

    is sap.m.select somehow different from this point of view?

    I mean, why JSONModelName should be give inside variable template in this case, but works fine for others, like sap.m.input, etc.

    Regards, Mindaugas

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 19 at 10:06 PM

    Hi All,

    I am not sure on the following: must I set a separate small model to dropdown and then other model to table or can I copy a content of dropdown-model to model of a table and then set one big model to table? I guess this is a source of problems..

    Thanks,

    Mindaugas

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 21 at 12:49 PM

    you don't have to put dropdown data in the table data, you can just bind to a single list.

    Add comment
    10|10000 characters needed characters exceeded