PDA

View Full Version : Combobox don't perform query



lucarossi
7 Aug 2012, 12:55 AM
Hi all,

I use extjs 4.1 along struts2 for the MVC pattern, and iBatis2 for the but when i click on my combobox the query is not performed.

this is the code i use for define my combobox:


Ext.define('App.mf.ClientCombo',{
extend: 'Ext.form.ComboBox',

allValue: null,
allLabel: null,
emptyValue: null,
emptyLabel: null,
additionalRecords: null,
clientQuery:null,
value: null,
historical: null,

queryMode: 'remote',
forceSelection : true,

constructor: function(config) {

Ext.define("ClientModel",{
extend: 'Ext.data.Model',
fields:[{name:'clientId', mapping:'clientId'},
{name:'description', mapping:'description'},
{name:'dummyName', mapping:'clientId'}]
});

config = config || {};

this.store = config.store || Ext.create('Ext.data.Store', {
model: "ClientModel",
proxy: {
noCache:false,
url: '<c:url value="/queryForList.action"/>',
type: 'ajax',
reader: {
type:'json',
root: 'list',
totalProperty: 'totalCount'
}
},
autoLoad:true
});

this.tpl = config.tpl || Ext.create('Ext.XTemplate',
'<tpl for="."><div class="search-item">',
'<h3><span style="width:260px;">{description}</span>{dummyName}</h3>',
'</div></tpl>'
);

Ext.applyIf(config, {
store:this.store,
tpl:this.tpl,
fieldLabel:'ClientId: ',
valueField:'clientId',
displayField:'dummyName',
triggerAction:'all',
typeAhead: false,
loadingText: '...',
minChars: 1,
pageSize:20,
listWidth: 390,
forceSelection: false,
itemSelector: 'div.search-item',
queryParam: '__q__'

});

// call parent constructor
this.callParent(config),

this.store.on('load', function(store, records, options) {

if (this.additionalRecords)
this.store.insert(0, this.additionalRecords);

if (this.emptyLabel)
store.insert(0, {clientId: this.emptyValue, dummyName: this.emptyLabel});

if (this.allLabel)
store.insert(0,{clientId: this.allValue, dummyName: this.allLabel});

}, this);

this.on('select', function(combo, record, index) {
var accountCombo = null;
if (this.accountComboId) {
accountCombo = Ext.getCmp(this.accountComboId);
if (accountCombo)
accountCombo.reloadAccountList(record.get('clientId'));
}

});

this.on('beforequery', function(e) {

var realQuery = 'lookupClients';

if (this.clientQuery)
realQuery = this.clientQuery;

if (e.query.length>=3) {
this.store.baseParams = {query:realQuery, clientId:e.query+'%', description:'%'+e.query+'%'};
} else
this.store.baseParams = {query:realQuery, clientId:e.query+'%'};

if (this.historical){
Ext.apply(this.store.baseParams,{historical: this.historical});
}
});
}

I also use this code for init the combo in the application:


var combo= Ext.create('App.mf.ClientCombo',{
id : 'clientId_id',
hiddenId : 'clientId_id_hidden',
hiddenName : 'clientId',
//accountComboId : 'accountId_id',
allValue : '',
allLabel : '[ ALL ]',
emptyValue : '[empty]',
emptyLabel : '[ EMPTY ]',
additionalRecords: [
{clientId: '', dummyName: 'None'}
]
});


I'm doing porting from extjs2 to extjs4.1 and i'm not sure to set all the parameter well.
Can anyone help me?