Extjs 4 how to set combobox value without loading a store - extjs

I have an ExtJS 4.2.1 form with a combobox.
xtype: 'container',
width: 360,
items: [{
xtype: 'combobox',
fieldLabel: 'Shift Code',
name: 'ShiftCode',
store: Ext.create('SoftHuman.store.catalog.ShiftCode'),
blankText: ' ',
allowBlank: false,
displayField: 'Description',
valueField: 'ShiftCode'
}]
The combo when I click on the trigger icon It will get the data from the store and then show the items, as show in the following image.
What I want to do is to set a value and display value in the combo when I load my form and then if the user clicks to expand the combo the store will get the items remotly like it does right now.
This is because I have this form with 25 combos and I don't want to load all them be before I show the form and then assign each combo value because the user won't change all combos values, maybe he will just change 2 or 3, so it doesn't make sense to load them all initially but I want to show the display value in the combo from my record.
Any clue?

You can insert the default value in store and set it a value
combo.getStore().insert(0, { "valueField": 0, "DisplayField": "All Properties" }, true);
combo.setValue(0);

What you are missing is the
queryMode: 'remote':
From the sencha docs
In queryMode: 'remote', the ComboBox loads its Store dynamically based upon user interaction.
This is typically used for "autocomplete" type inputs, and after the user finishes typing, the Store is loaded.
A parameter containing the typed string is sent in the load request. The default parameter name for the input string is query, but this can be configured using the queryParam config.
In queryMode: 'remote', the Store may be configured with remoteFilter: true, and further filters may be programatically added to the Store which are then passed with every load request which allows the server to further refine the returned dataset.
You can also use queryDelay if you want too.
Here's an example I pulled from my code.
{
xtype: 'combo',
itemId: 'totalSearchCombo',
width: 200,
emptyText: 'Total Search',
typeAhead: true,
editable: true,
hideLabel: true,
hideTrigger: true,
store: 'dropDownList_s',
mode:'remote',
displayField: 'display_nm',
anchor: '100%',
matchFieldWidth: false,
listConfig:
{
width: 195,
loadingText: 'Searching...',
emptyText: 'No matching items found, or not enough characters entered.',
getInnerTpl: function () {
var tpl = '<div>{display_nm}</div>';
return tpl;
}
},
//pageSize: 15,
listeners: {
}
}

The solution was to set the following methods:
combo.setValue('here the value');
combo.setRawValue('here the value to display');

Related

ExtJS ViewModel setData() only works when data is different

I have 2 combos: The second one is on a form and depends on the first one. To do this, the value of the second one is binded to a ViewModel data property. I made a button to reset the form and reassign the value of the second combo with the value of the first one (It might be change).
The problem is when I do the following: I change the value of the first combo. When I click the button the first time, it works (the second combo is changed). But when I click the second time (with both combos with the same value), the second combo is emptied. It doesn't seem to work if the value of the second combo is the same as that of the first combo. What I am doing wrong?
Here is my code in a fiddle
When the value of the first combo corresponds to the value of the second combo, the viewmodel does not change, which is logical. We don’t need extra operations. Accordingly, the value is not substituted in the second combobox and it only makes a reset.
To force a model update, you must inform her about this using the notify method
You can see that behavior on my fiddle
Look at callstack when values are matches and don't mathes.
Try it, I hope it'll help.
Use Component Query Selector to direct set the value in combo box.
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
]
});
var viewmodel = Ext.create('Ext.app.ViewModel', {
data: {
state: 'AL'
}
});
var refCombo = Ext.create('Ext.form.field.ComboBox', {
store: states,
queryMode: 'local',
itemId: 'refCombo',
displayField: 'name',
valueField: 'abbr',
editable: false,
value: 'AL',
renderTo: Ext.getBody()
});
Ext.create('Ext.form.Panel', {
renderTo: Ext.getBody(),
viewModel: viewmodel,
items: [{
xtype: 'combo',
store: states,
queryMode: 'local',
itemId: 'refCombo2',
displayField: 'name',
valueField: 'abbr',
editable: false,
bind: {
value: '{state}'
}
}, {
xtype: 'button',
text: 'CLICK',
handler: function(button) {
button.up('form').getForm().reset();
viewmodel.setData({'state': refCombo.getValue()})
let refCombo2 = Ext.ComponentQuery.query('#refCombo2')[0];
refCombo2.setValue( refCombo.getValue());
}
}]
});

ExtJS Bind Filter and select default value on child combo box

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.
}
}
}

Avoid to display the ValueField in the Grid Edit row editing

I'm trying to edit the Gridpanel with the combobox items.
When I try selecting a value to edit and click on the other cell the value field appears in the cell as seen in the image attached, I want to display the description of the items and keep the valueField hidden from appearing . How would I be able to show the description always and edit,update the panel. knowing that I can update the data with the id(valueField which is appearing in the second part of image) only.
please help. thanks in advance.
Small piece of that grid
{
header: 'Field Time Distrib',
xtype: 'gridcolumn',
dataIndex: 'feild_distributor',
flex: 1,
editor: {
xtype: 'combobox',
allowBlank: true,
displayField: "description",
valueField: "distribsrcid",
queryMode: 'local',
mapperId: 'getfeildDistrib',
lastQuery: '',
forceSelection: true,
listeners: {
expand: function () {
var call = this.up('timegrid[itemId=feilddTimeGrid]').getSeletion().selection.record.data.fieldname.trim();
this.store.clearFilter();
this.store.filter({
property: 'call',
value: call,
exactMatch: true
})
}
}
}
}
One solution I can suggest you , Use renderer function of column identify if it is number ,If number get the respective name from the store and return the name ... check my fiddle. check the fiddle for my example

ExtJS grid combo renderer not working

I have a grid in my ExtJS 4.2.1 application that has an editable column with combo editor.
I need to render the column with the value from the DisplayField of the combo but the comboStore.getCount() = 0
Here is my grid:
Ext.define('App.employee.Grid', {
extend: 'Ext.grid.Panel',
requires: ['Ext.grid.plugin.CellEditing'],
alias: 'widget.employee.grid',
config: {
LocationId: 0
},
initComponent: function() {
var me = this,
store = me.buildStore(),
comboStore = Ext.create('App.store.catalog.Location', { autoLoad: true });
me.rowEditing = Ext.create('Ext.grid.plugin.RowEditing', {
clicksToMoveEditor: 1,
autoCancel: false,
listeners: {
edit: function(editor, e) {
}
}
});
me.cellEditing = new Ext.grid.plugin.CellEditing({
clicksToEdit: 1
});
Ext.applyIf(me, {
plugins: [me.rowEditing],
columns: [{
xtype: 'rownumberer',
text: '#',
width: 50,
sortable: false,
align: 'center'
//locked: true
},{
text: 'Number',
dataIndex: 'EmployeeNumber',
align: 'center',
width: 90
}, {
text: 'Name',
dataIndex: 'EmployeeName',
flex: 1
}, {
text: 'Location',
dataIndex: 'LocationId',
width: 140,
renderer: function(value) {
// HERE!!!
// me.comboStore.getCount() = 0 so I never get a record
var record = me.comboStore.findRecord('LocationId', value);
return record.get('Description');
},
editor: {
xtype: 'combobox',
typeAhead: true,
triggerAction: 'all',
store: comboStore,
displayField: 'Description',
valueField: 'LocationId',
queryMode: 'local',
listConfig: {
width: 250,
// Custom rendering template for each item
getInnerTpl: function() {
return '<b>{Code}</b><br/>(<span style="font-size:0.8em;">{Description}</span>)';
}
}
}
}],
store: store,
});
me.callParent(arguments);
}
});
The problem is in the renderer function because the comboStore is always empty. The strange thing is that in my view If I click to edit the row and open the combo the combo has values.
[UPDATE]
What I think is that my comboStore has a delay when loading so the renderer is fired before the comboStore gets loaded. I figure this out because if I debug in chrome and I wait a few seconds, then it works... but don't know how to force to wait until comboStore is loaded.
Any clue on how to solve this? Appreciate any help.
A couple of solutions:
Ensure that the combo store is loaded before the grid store. This can be done by loading the combo first and from load event of its store trigger the grid store load. The disadvantage is that it adds unnecessary delay so this method impairs the user experience.
Load all needed stores in one request. It requires a bit of coding but it saves server roundtrip so it's a very valuable approach. Store loadData method is used to actually load store with the received data. You would, of course, first call it on combo, then on the grid.
The best method that I use almost exclusively is to turn the whole thing upside down and link display field to the store, not value field. Server must return both display and value fields in the grid store and a little piece of code that updates both fields in the grid store after editing is complete is required. This method is demonstrated here: Remote Combo in ExtJS Grid

Ext.js Combo Box - List issue

I want to create an application where the combo box should look like first image below. But when I use a list for the combo box it comes out looking like the second image. The list is not fully shown - it is getting cut. Please suggest me which property to use? The code is as below:
items: [{
xtype: 'combobox',
fieldLabel: 'Location',
displayField: 'name',
forceSelection: true,
pageSize: 10,
store: 'SalesOrderManager.store.LocationStore',
typeAhead: true,
valueField: 'id',
id: 'LocationComboBox'
}]
What it should look like:
What I'm getting instead:
The full code can be viewed in this Fiddle.
Are you talking about the picker width? I think you want:
matchFieldWidth: false,
listConfig: {
width: 250
}

Resources