ExtJS Bind Filter and select default value on child combo box - extjs

I am trying to create two combo boxes. The first one shows the country names and the second one shows provinces/states. The idea is to filter the second combo based the selection on first one and put the value of 'VisitingCountryProvince' as the default selection.
The problem with the below code is, it is not selecting the default value based on the first combo box. If I remove the bind filter, the second combo box shows the correct value of 'VisitingCountryProvince'.
Any idea?
{
xtype: 'fieldset',
title: 'Visiting Country',
layout: 'anchor',
anchor: '-10',
collapsible: false,
defaults: {
xtype: 'combo',
labelStyle: 'font-weight: bold;',
flex: 1,
anchor: '0',
editable: false,
forceSelection: true,
allowBlank: false,
emptyText: 'Select...',
queryMode: 'local',
},
items: [{
name: 'VisitingCountry',
fieldLabel: 'Main',
reference: 'visitingCountryFieldRef',
publishes: 'value',
store: {
type: 'arraydropdownstore'
},
valueField: 'value',
displayField: 'value'
}, {
name: 'VisitingCountryProvince',
fieldLabel: 'Sub',
store: {
type: 'array',
fields: ['value', 'countryName']
},
bind: {
filters: {
property: 'countryName',
value: '{visitingCountryFieldRef.value}'
}
},
valueField: 'value',
displayField: 'value'
}]
},
The closest answer to the issue I could find is in here, How to use combo "publishes" value & bindings to filter store on another combo
I just figured out that, I can do either filter or select a default value, not both. How do I filter and bind a default value from the filtered list?

You need to write your logic of filtering the values of second combo store in the "select" event handler of the first combo box.
{
name: 'VisitingCountry',
fieldLabel: 'Main',
reference: 'visitingCountryFieldRef',
publishes: 'value',
store: {
type: 'arraydropdownstore'
},
valueField: 'value',
displayField: 'value',
listeners:{
select:function(){
//Access the second[bound to second combobox]store and apply the
//filter, Also there are arguments for select event handler, for this
//Please refer docs.sencha.com for extjs version you are using.
}
}
}

Related

ETXJS 6.2.0 Combobox Filter Returns Mulitple Values

I have a combobox that's filtering a store based on an id from another drop down. However the filter seems to be returning all the values that START with the selected id.
xtype: 'combobox',
name: 'actor',
fieldLabel: 'Actor',
typeAhead: true,
forceSelection: true,
queryMode: 'local',
displayField: 'name',
valueField: 'id',
bind: {
store: 'actorStore',
value: 'actor.id',
filters: [{
property: 'customerId',
value: '{customer.value}',
disableOnEmpty: true
}
Try to set the filter's operator, see here:
filters: [{
property: 'customerId',
value: '{customer.value}',
operator: '=',
disableOnEmpty: true
}]
(I don't know your ExtJS version, but I am not sure the combobox has a filters config, but the store surely has.)

How to use record from renderer function as store for combo inside editor ExtJs Grid

I have a grid with with cell editing plugin:
Ext.define('MyGrid', {
extend: 'Ext.grid.Panel',
title: 'MyGrid',
emptyText: __('no_data'),
plugins: {
ptype: 'cellediting',
clicksToEdit: 1
},
columns: [
{
text: 'Email',
dataIndex: 'email',
editor: {
xtype: 'combo',
queryMode: 'local'
},
renderer: function(value) {
// this I wont to use value as store combo
return value;
}
}
]
});
Value in renderer function is an array. How to use it as store in combo inside editor?
I solved my problem by using widget column with combobox.
{
xtype: 'widgetcolumn',
flex: 1,
text: 'Email',
editor: {},
widget: {
xtype: 'combo',
queryMode: 'local',
displayField: 'email',
valueField: 'email',
editable: false,
value: 0,
listeners: {
afterrender: 'afterComboEmailRender',
change: 'onComboEmailChange'
}
}
}
And I dynamically set store from cell record to combo after it render.
I am not sure if the value in the column would be the value that the user selects from the combobox. If this was the case and the values that you are selecting from will be the same for all the columns, then you can create a store for that combobox and bind it.

ExtJs dropdown list with two color rows

I have ExtJs combo drop down list. I want to two-color(odd as red and even as green)row list when combo is span
Note: single row has multi(more than one line) lines
Is this possible with ExtJS 4.2? if yes how can i do that.
{ xtype: 'combobox',
id: 'mycbo',
itemId: 'mycbo',
fieldLabel: 'Name',
name: 'id',
tabIndex: 5,
allowBlank: false,
displayField: 'NAME',
forceSelection: true,
queryMode: 'local',
store: 'STORE',
valueField: 'ID'
},
You should use listConfig config to change behaviour of combobox picker. (For more information: http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.form.field.ComboBox-cfg-listConfig)
In snippet below I'm setting class 'odd' and 'even' to each option in the combobox. Then I can style it with CSS.
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local',
displayField: 'name',
valueField: 'abbr',
listConfig: {
getInnerTpl: function(displayField) {
return '<tpl if="xindex%2==0"><div class="odd"></tpl><tpl if="xindex%2==1"><div class="even"></tpl> {' + displayField + '} </div>';
}
},
renderTo: Ext.getBody()
});
Take a look at the Custom Item Templates example here - http://docs.sencha.com/extjs/4.2.0/#!/example/form/combos.html and look at the source code and how the listConfig is used.
You should be able to use this approach for achieving custom styling of the list items that appear

ExtJS remote combo - add additional filter parameters (from other combo selection)

I have 2 combos, I want to force to select the first combo (employer combo), after it's selected then the combo 2 (employee combo) is enable.
ExtJS 4.2.1
The code of the combos is:
{
xtype: 'combobox',
store: Ext.create('SoftHuman.store.catalog.Employer', {
autoLoad: true
}),
displayField: 'Description',
valueField: 'EmployerId',
fieldLabel: 'Company',
name: 'EmployerId',
queryMode: 'local',
allowBlank: true
}, {
xtype: 'combobox',
anchor: '100%',
store: Ext.create('SoftHuman.store.employee.EmployeeCombo'),
displayField: 'FullName',
valueField: 'EmployeeId',
queryMode: 'remote',
fieldLabel: 'Employee',
editable: true,
hideTrigger: true,
queryParam: 'searchStr',
name: 'EmployeeId',
allowBlank: true,
listConfig: {
loadingText: 'Searching...',
// Custom rendering template for each item
getInnerTpl: function () {
return '<b>{EmployeeNumber}</b> / {FullName}';
}
}
},
Right now my remote combo employee combo send into the query param "searchStr" that is the string typed in the combo. I need to pass also the selection from combo 1 (employer combo).
How can I achieve this? Thanks.
use something like this.
Ext.ComponentQuery.query('EmployerId').value
Ext.getCmp('EmployerId').value
var empValue = getComponent('EmployerId').value
if .value not work then try getValue() method.
Hope this helps.
in your second component(EmployeeId) add configuration disabled:true on load.
then add afterrender listener to the first one. and then set the other combo available.
Then do this............................................................................
{
xtype: 'combobox',
store: Ext.create('SoftHuman.store.catalog.Employer', {
autoLoad: true
}),
displayField: 'Description',
valueField: 'EmployerId',
fieldLabel: 'Company',
name: 'EmployerId',
queryMode: 'local',
allowBlank: true
listeners: { <---------------------here
select: function(combo, selection) {
if (combo.getValue() != undefined) {
Ext.ComponentQuery.query('EmployeeId').setDisabled(false)
} <----------------------------- to here
}, {
xtype: 'combobox',
anchor: '100%',
store: Ext.create('SoftHuman.store.employee.EmployeeCombo'),
displayField: 'FullName',
valueField: 'EmployeeId',
queryMode: 'remote',
fieldLabel: 'Employee',
editable: true,
disabled:true, <------------add this
hideTrigger: true,
queryParam: 'searchStr',
name: 'EmployeeId',
allowBlank: true,
listConfig: {
loadingText: 'Searching...',
// Custom rendering template for each item
getInnerTpl: function () {
return '<b>{EmployeeNumber}</b> / {FullName}';
}
}
},
Hope this helps :)

Extjs setValue of combobox doesn't show displayField

I'm setting the value of a combobox using combo.setValue(value) passing an id that is linked to a displayField. The problem is that I want to show the displayField not the id, it seems like extjs does not make the conversion.
{
xtype: 'combobox',
fieldLabel: 'Categoria',
name: 'categoria',
labelAlign: 'top',
allowBlank: false,
blankText: 'Campo obbligatorio',
typeAhead: true,
displayField: 'categoria',
valueField: 'id',
store: comboCategoriaStore,
columnWidth: .2,
margin: 5,
listeners: {
select: {
fn: me.onFieldBlur,
scope: me
}
}
}

Resources