cancel
Showing results for 
Search instead for 
Did you mean: 

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

0 Kudos

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

former_member182862
Active Contributor
0 Kudos

can it be "{/rowDropdown}"?

maheshpalavalli
Active Contributor
0 Kudos

Hi Mindaugas Kazlauskas

What is the format of the data in the oModel you are binding to select control?

BR,

Mahesh

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

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

Answers (5)

Answers (5)

junwu
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

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

junwu
Active Contributor
0 Kudos

no, model name always has to be there

Abdul_Waheed
Contributor
0 Kudos

Try below

{JSONModelName>rowDropdown}

0 Kudos

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