I have added quicktip(tooltip) for the combox by using tpl as below,
'<tpl for="."><div ext:qtip="{text}" class="x-combo-list-item">{text}</div></tpl>'
But after adding this, the combobox doesn't mark (in blue) the selected entries. ie, Before i am adding the tooltip, the selected entries can be seen as marked or selected (as blue color for me). But now its not working(the selected enitries are not seeing as selected).
Here is my code,
{
name : name,
hideOnSelect : false,
triggerAction : 'all',
mode : 'local',
width : size,
tpl :'<tpl for="."><div ext:qtip="{text}" class="x-combo-list-item">{text}</div></tpl>',
store : new Ext.data.SimpleStore({
id : 0,
fields : ['value','text'],
data : data
}),
listWidth : 400,
valueField : 'value',
displayField : 'text'
}
<---before
<---after
Any help is must appreciated...Thank you.
displayTpl should work too:
{
name: name,
hideOnSelect: false,
triggerAction: 'all',
mode: 'local',
width: size,
store: new Ext.data.SimpleStore({
id: myCombo,
fields: ['value','text'],
data: data
}),
listWidth: 400,
valueField: 'value',
displayField: 'text',
displayTpl: '<tpl for="."><div ext:qtip="{text}">{text}</div></tpl>'
}
UPDATE
Found the issue! You had to init the QuickTips first. The rest of your code was fine! Here is a working fiddle
Ext.QuickTips.init();
var cb = new Ext.form.ComboBox({
name: name,
hideOnSelect: false,
triggerAction: 'all',
mode: 'local',
width: 200,
store: new Ext.data.JsonStore({
id: "myCombo",
fields: ['value', 'text'],
data: [
{ value: 1, text: 'one'},
{ value: 2, text: 'two'},
{ value: 3, text: 'three'}
]
}),
listWidth: 250,
valueField: 'value',
displayField: 'text',
renderTo: Ext.getBody(),
tpl: '<tpl for="."><div ext:qtip="{text}" class="x-combo-list-item">{text}</div></tpl>'
});
can you try this...
{
name : name,
hideOnSelect : false,
triggerAction : 'all',
mode : 'local',
width : size,
store : new Ext.data.SimpleStore({
id : myCombo,
fields : ['value','text'],
data : data
}),
listWidth : 400,
valueField : 'value',
displayField : 'text',
listConfig: {
getInnerTpl: function() {
return '<div data-qtip="{text}">{value}</div>';
}
}
}
Related
I am trying to set a default value in a ComboBox in ExtJS 3.4 I have tried to set value: 'Standard' in the ComboBox config, but that only places a string in the box. I did some digging around and tried to setup the afterrender function, but still haven't gotten it to populate. The goal is to get the box to actually select the value and populate the box with the Json data, so that the user is able to select from subsequent ComboBoxes.
var hatComboStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [
'BIN_ID',
'BIN_DESC'
],
baseParams: {
method: 'post'
},
url: 'json_bin_hat.php'
});
var hatCombo = new Ext.form.ComboBox({
allowBlank: false,
autoSelect: true,
displayField: 'BIN_DESC',
emptyText: 'Select a hat...',
fieldLabel: 'Hat',
forceSelection: false,
hiddenName: 'hatId',
itemId: 'hatId',
listEmptyText: 'No records found',
listeners: {
afterrender: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
select: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
focus: function(combo) {
binCombo.clearValue();
}
},
mode: 'remote',
msgTarget: 'side',
name: 'hatDesc',
store: hatComboStore,
submitValue: true,
triggerAction: 'all',
valueField: 'BIN_ID'
});
Anyone have any ideas? Thanks for your help!
I've got it to work using an override method.
Basically, the displayValue is what I wanted to display ('Standard') and the value is what I wanted to execute (value: 1). Apparently, the remote store is a little tricky to work with, so that's why the override was necessary.
var hatComboStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [
'BIN_ID',
'BIN_DESC'
],
baseParams: {
method: 'post'
},
url: 'json_bin_hat.php'
});
var hatCombo = new Ext.form.ComboBox({
allowBlank: false,
autoSelect: true,
displayField: 'BIN_DESC',
displayValue: 'Standard',
emptyText: 'Select a hat...',
fieldLabel: 'Hat',
forceSelection: false,
hiddenName: 'hatId',
itemId: 'hatId',
listEmptyText: 'No records found',
listeners: {
afterrender: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
select: function(combo, record, index) {
var hat = combo.getValue();
binCombo.store.baseParams.hat = hat;
},
focus: function(combo) {
binCombo.clearValue();
}
},
mode: 'remote',
msgTarget: 'side',
name: 'hatDesc',
store: hatComboStore,
submitValue: true,
triggerAction: 'all',
valueField: 'BIN_ID'
value: 1
});
//Override method to default hatCombo value to 'Standard' while underlying value = 1
Ext.override(Ext.form.ComboBox, {
initValue: Ext.form.ComboBox.prototype.initValue.createSequence(function() {
if (this.mode == 'remote' && !!this.valueField && this.valueField != this.displayField && this.displayValue) {
if (this.forceSelection) {
this.lastSelectionText = this.displayValue;
}
this.setRawValue(this.displayValue);
}
})
});
Looks like the value prop is not working for remote stores. Probably the combo is rendered before the store has loaded. You can set the value after the store has loaded.
This works for me (tested as an ExtJS 3.4 fiddle).
var hatComboStore = new Ext.data.JsonStore({
autoLoad: true,
fields: [
'id',
'title'
],
url: 'https://jsonplaceholder.typicode.com/todos'
});
var hatCombo = new Ext.form.ComboBox({
fieldLabel: 'Hat',
store: hatComboStore,
displayField: 'title',
valueField: 'id',
mode: 'local',
submitValue: true,
triggerAction: 'all',
// Apparently does not work with remote store.
// value: '1'
});
hatComboStore.on('load', () => hatCombo.setValue('1'));
new Ext.form.FormPanel({
items: hatCombo,
renderTo: Ext.getBody()
});
see example of setting default value:
Combo config:
{
triggerAction: 'all',
id: 'dir_id',
fieldLabel: 'Direction',
queryMode: 'local',
editable: false,
xtype: 'combo',
store : dirValuesStore,
displayField:'name',
valueField:'id',
value: 'all',
width: 250,
forceSelection:true
}
source: Extjs 4 combobox default value
I use Ext js 3.4 combobox finder.
Suppose that the combobox's store uses pagination.
As first, when I select some item, it gives me i.e.: getValue() => 1000 and getRawValue() => "Item Name", but after I change pagination (without selecting any item) the getValue() method returns "Item Name".
Can anyone help me?
Combobox = Ext.extend(Ext.form.ComboBox, {
allowBlank: false,
autoSelect: false,
baseParams: {},
cls: "remote-server-finder",
displayField: 'name',
emptyText: "",
forceSelection: false,
itemSelector: 'div.remote-server-finder-item',
minChars: 0,
pageSize: 10,
queryDelay: 10,
store: null,
triggerAction: 'all',
typeAhead: true,
valueField: 'id',
minListWidth: 235,
maxHeight: 400,
/**
* Setup the data store and template for the finder.
*/
initComponent: function () {
this.blankText = helpsys.locale.javascript.field_required;
this.loadingText = helpsys.locale.common.searching;
this.listEmptyText = helpsys.locale.javascript.no_matching_record;
this.store = new Ext.data.JsonStore({
baseParams: this.baseParams,
fields: [
{
name: 'id'
},
{
name: 'name'
},
{
name: 'description'
},
{
name: 'type'
}
],
idProperty: 'id',
proxy: new Ext.data.HttpProxy({
url: this.url,
method: 'GET',
listeners:{
beforeload:{
scope:this,
fn:function(dp, params){
if(dp.activeRequest['read']){
dp.activeRequest['read'].conn.abort();
}
}
}
}
}),
root: 'items',
totalProperty: "totalResultsAvailable"
});
this.tpl = new Ext.XTemplate('<tpl for="."><div class="remote-server-finder-item finder-item x-combo-list-item">',
'<div class="remote_server_finder_text finder_text">', '<h2 class="name">{name}</h2>', '<p class="description">{description}</p>', '</div>', '</div></tpl>');
);
}
I have a combobox I can get all data I want but when i enter a letter, the data should be choosen in combobox
forexample,my variables: ankara, aston, amasya, bolu, berlin, ....
When i enter 'a' letter ankara should be selected. if i enter 'as' word aston should be selected how can i do it? thanks..
new Ext.form.ComboBox({
id : 'il3',
fieldLabel: dil('B Merkez İli'),
hiddenName : 'b_il_id_hid',
name : 'b_il_id',
store: ilStore,
valueField:'id',
queryMode: 'local',
displayField:'isim',
typeAhead: true,
triggerAction: 'all',
emptyText: dil('İl Seçiniz...'),
selectOnFocus:true,
anchor: '100%',
listeners:{
select:{
fn:function(combo, value) {
var modelCmp = Ext.getCmp('ilce3');
modelCmp.setDisabled(false);
modelCmp.store.removeAll();
modelCmp.setValue('');
modelCmp.store.reload({
params: {
id: combo.getValue()
}
});
}
}
},
allowBlank:false
})
store:
var ilStore = new Ext.data.JsonStore({
root: 'rows',
totalProperty: 'results',
idProperty: 'id',
remoteSort: true,
autoLoad : true,
fields: [
'id', 'isim'
],
baseParams:{
'tip':'il'
},
listeners:{
beforeload:function(dukan,nesne){
var modelCmp = Ext.getCmp('id-faz-yon1');
dukan.baseParams.faz = modelCmp.getValue();
},
keyup: function() {
this.store.filter('isim', this.getRawValue(), true, false);
}
},
proxy: new Ext.data.HttpProxy({
url: 'phps/sabit_agac_arama.php?lang=dil(lang)',
method : 'POST'
})
});
Add queryMode: 'local', to the config.
See the example in the API
I am new to ExtJS and need to put a ComboBox in an EditorGridPanel.
My code so far does not create the combobox in the EditorGridPanel and the EditorGridPanel does not display as well.
Here is the code and thanks for your help. capturetheflag
/*==== INVOICE DATA START =======================================================*/
/* create the ComboBox editor */
var idCombo = new Ext.form.ComboBox({
id: 'id',
valueField: 'id',
displayField:'id',
store: '', //what do I store here??
triggerAction: 'all'
});
var idRenderer = function(value,metaData,record){
// try record.data.teacher here
return "displayValue"
var iLineItemCM = new Ext.grid.ColumnModel([
{
id: 'i_line_item_id',
header: 'Line Item ID',
dataIndex: 'i_line_item_id',
width: 80,
editor: this.idCombo(),
renderer:idRenderer
}
,{
id:'i_line_item_name',
header: "Line Item Name",
dataIndex: 'i_line_item_name',
width: 315,
resizable: true,
align: 'center',
editor: new Ext.form.TextArea({
allowBlank: false
})
}
,{
header: "Amount",
dataIndex: 'i_line_item_amt',
width: 80,
align: 'right',
renderer: 'usMoney',
editor: new Ext.form.NumberField({
allowBlank: false,
allowNegative: false,
maxValue: 100000
})
}
]);
var iLineItemRec =
new Ext.data.Record.create([
{
name: 'i_line_item_id' ,
mapping: 'i_line_item_id' ,
type: 'string'
}
,{
name: 'i_line_item_name' ,
mapping: 'i_line_item_name' ,
type: 'string'
}
,{
name: 'i_line_item_amt' ,
mapping: 'i_line_item_amt' ,
type: 'string'
}
]);
var iLineItemStore = new Ext.data.Store({
url: '',
reader: new Ext.data.JsonReader({
root: 'rows'
},
iLineItemRec
)
});
var iLineItemGrid = new Ext.grid.EditorGridPanel({
id: 'iLineItemStore',
store: iLineItemStore,
cm: iLineItemCM,
cls: 'iLineItemGrid',
width: 'auto',
height: 'auto',
frame: true,
//title:'Edit Plants?',
//plugins:checkColumn,
clicksToEdit:1,
viewConfig: {
//forceFit: true
autoFit:true
},
tbar: [{
text: 'Add',
tooltip:'Add the line item',
handler : function(){
var r = new iLineItemRec({
i_line_item_name: '',
i_line_item_amt: ''
});
iLineItemGrid.stopEditing();
iLineItemStore.insert(0, r);
iLineItemGrid.startEditing(0, 0);
}
},
{
text: 'Delete',
tooltip:'Remove the selected line item',
handler: function(){
iLineItemGrid.stopEditing();
var r = iLineItemGrid.getSelectionModel().getSelectedCell();
iLineItemStore.removeAt(r[1]);
}
}
]
});
/////////////////// CODE ENDS
You need to create a data store and bind that to your combobox. Then in the combo config, you can tell it which field from the store you want to display and which field you want for the value. Here is an example from ExtJS 4 API Docs:
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'], // fields that your data consists of
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});
// Create the combo box, attached to the states data store
var combo = Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states, // here you use the store
queryMode: 'local',
displayField: 'name', // you tell your combobox which field to display from the store
valueField: 'abbr', // you tell your combobox which field to use for value from the store
renderTo: Ext.getBody()
});
If you use combo.getValue(), and if e.g. "Alaska" were selected in your combobox, it would return "AK". You can also use the same field as displayField and valueField if you like.
I have a tbar inside a grid panel like this:
This is the code that produces it:
var grid = new Ext.grid.GridPanel({
region: 'center',
style: 'margin: 10px',
store: new Ext.data.Store({
data: myData,
reader: myReader
}),
title: 'Testing',
tbar: ['Filters:', {
width: 100,
xtype: 'combo',
mode: 'local',
value: 'en',
triggerAction: 'all',
forceSelection: true,
editable: false,
fieldLabel: 'Produkt',
name: 'language',
hiddenName: 'language',
displayField: 'name',
valueField: 'value',
store: new Ext.data.JsonStore({
fields : ['name', 'value'],
data : [
{name : 'German', value: 'de'},
{name : 'English', value: 'en'},
{name : 'French', value: 'fr'}
]
})
}],
What do I need to change so that the dropbox is right-aligned instead of left-aligned?
Addendum
thanks #dogbane, that works perfectly, here's how I right aligned both text and dropdown:
tbar: [
{xtype: 'tbfill'},
'Filters:',
{
width: 100,
xtype: 'combo',
mode: 'local',
...
Try:
{xtype: 'tbfill'}, // or '->'
See the docs for Ext.Toolbar.Fill.