PDA

View Full Version : Dynamically Changing Combobox displayField Property



raśl.7
14 Jan 2014, 7:13 AM
Hello,

I have a problem about changing combobox's displayField property dynamically.




var cmb = Ext.create('Ext.form.field.ComboBox', {
...
});

cmb.displayField = 'blabla';

cmb.getStore().load();




This code is not working appropriately. (Not showing the field 'blabla').

Thanks for your attention.

scottmartin
14 Jan 2014, 3:09 PM
Changing the config will not have any affect.

You can set different templates for the display.

Have a look at this example:
http://jsfiddle.net/rixo/Ubf77/

raśl.7
14 Jan 2014, 11:28 PM
Thanks for your reply but changing templates is not a solution for my problem because another problem occurs after selection. When user selects an item, displayField value of this item will be displayed on the combobox.

KJedi
15 Jan 2014, 12:55 AM
I don't think this is possible in combobox. Can you provide a context please? Why do you need this feature? I'm sure there is another way of achieving what you need.

f.baron
15 Jan 2014, 2:10 AM
Thanks for your reply but changing templates is not a solution for my problem because another problem occurs after selection. When user selects an item, displayField value of this item will be displayed on the combobox.

You can also manage the selected item template by using the displayTpl (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.ComboBox-cfg-displayTpl) config of combobox.

hooger
14 Jan 2015, 7:05 AM
I have the same issue and same need.

Use Case:

I have two combo boxes.

One combo box that lets me select security id source (ISIN, CUSIP, SEDOL)

Other that is for security id. This combo box is a realtime typeahead remote query. A listConfig itemTpl has been applied so that when the user types the search parameters, they are presented with four columns of data (ISIN, CUSIP, SEDOL, Description) for the same security.

Each record in the store (the store's model) has these four properties. For the same security, the user should be able to determine which security source needs to be used. That is addressed by the first drop down. So on changing the security source drop down, I want the displayField and valueField to change dynamically.

Does anyone have a solution for this issue yet?

I am thinking it should be as simple as binding, but it is not:

bind: {
displayField: '{securitySource.value}',
valueField: '{securitySource.value}'
}

f.baron
14 Jan 2015, 8:12 AM
I'm not sure it's the case, couldn't you define a 'display' field in your model and put the logic in its 'convert' function? The combo takes simply displayField: 'display'.

hooger
14 Jan 2015, 8:20 AM
That is the next thought process. It works when using the first drop down and then the second drop down. If the security id (2nd drop down) is already selected and the user decides to change the security source (1st drop down) what logic can i place in select listener to "refresh" the model to recalculate the display value so that it is properly updated.

f.baron
14 Jan 2015, 8:44 AM
Maybe
combo.getStore().reload(). Anyway I think it's better to "refresh" the store's model of the 2nd combo than to change the combo properties.

hooger
14 Jan 2015, 8:56 AM
reloading the store doesn't work.

I think it makes perfect sense to be allowed to update the displayField and valueField properties of a combobox on the fly (via binding) especially since the models used for the data can be complex (contain many fields).

k_cire0426
23 Mar 2015, 12:47 AM
I need this functionality as well. Does anyone made a workaround?

yeghikyan
24 Mar 2015, 2:40 AM
You can use the following override to add the missing functionality:
k66

P.S.
bad, sehr bad practice :-|

UPDATED: Ops sorry it is 5.x version.... moment bitte

yeghikyan
24 Mar 2015, 3:29 AM
And for 4.2 you can use the following code:
k6a