How can I set the legend in Ext JS ItemSelector/Multiselect control?
I have the following multiselect control in a Ext JS form which looks like this:
How can I change the two legends "Available" and "Selected"?
I see in the file ItemSelect.js
where I could set these once internally:
But how can I set these legend labels from the calling code so that every time I call this control, I can give it new legend names, e.g. something like:
msConfig[0].legend = 'verfügbar';
msConfig[1].legend = 'ausgewählt';
Calling code:
}, {
xtype: 'itemselector',
name: 'itemselector',
fieldLabel: 'ItemSelector',
width: 700,
imagePath: 'images/multiselect/',
multiselects: [{
width: 开发者_Python百科250,
height: 200,
store: new Ext.data.ArrayStore({
data: [[123,'One Hundred Twenty Three'],
['1', 'Two'], ['2', 'One'], ['3', 'Three'], ['4', 'Four'], ['5', 'Five'],
['6', 'Six'], ['7', 'Seven'], ['8', 'Eight'], ['9', 'Nine']],
fields: ['value','text'],
sortInfo: {
field: 'value',
direction: 'ASC'
}
}),
displayField: 'text',
valueField: 'value'
},{
width: 250,
height: 200,
store: [['10','Ten'],['11','Eleven'],['12','Twelve']],
tbar:[{
text: 'clear',
handler:function(){
simple_form.getForm().findField('itemselector').reset();
}
}]
}]
},
Well, it is configurable through the config when you create your itemselector in the form panel. Here is how I modify to get the desired result:
multiselects: [{
legend: 'XYZ',
width: 250,
height: 200,
store: ds,
displayField: 'text',
valueField: 'value'
},{
legend: 'ABC',
width: 250,
height: 200,
store: [['10','Ten']],
tbar:[{
text: 'clear',
handler:function(){
isForm.getForm().findField('itemselector').reset();
}
}]
}]
By using the legend property, you will be able to modify the fieldset's title. Now, If you plan to set these after the inital rendering of the component. Here is how the result will look like:
Looking at the code of the Ext.ux.form.ItemSelector.onRender I noticed the comment "//ICON HELL!!"
which doesn't bode well for Ext.override'ing the onRender method on the itemSelectors without actually copying all the ICON HELL over.
The best way you could go is add a render
or afterrender
event-listener to your ItemSelector and therein try to access the fieldset instance within the MultiSelect components in your ItemSelector and changing the title.
But come to think of it ... this ItemSelector Component needs some urgent refactoring and this should be configurable through the config by default.
Anyway, try this ... you can run this by putting it in the default multselect examples that come with the ExtJS3 download. Notice the render listener and the title config option i added to the multiselects.
/*!
* Ext JS Library 3.3.1
* Copyright(c) 2006-2010 Sencha Inc.
* licensing@sencha.com
* http://www.sencha.com/license
*/
Ext.onReady(function(){
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var ds = new Ext.data.ArrayStore({
data: [[123,'One Hundred Twenty Three'],
['1', 'One'], ['2', 'Two'], ['3', 'Three'], ['4', 'Four'], ['5', 'Five'],
['6', 'Six'], ['7', 'Seven'], ['8', 'Eight'], ['9', 'Nine']],
fields: ['value','text'],
sortInfo: {
field: 'value',
direction: 'ASC'
}
});
/*
* Ext.ux.form.ItemSelector Example Code
*/
var isForm = new Ext.form.FormPanel({
title: 'ItemSelector Test',
width:700,
bodyStyle: 'padding:10px;',
renderTo: 'itemselector',
items:[{
xtype: 'itemselector',
name: 'itemselector',
fieldLabel: 'ItemSelector',
imagePath: '../ux/images/',
multiselects: [{
width: 250,
height: 200,
store: ds,
displayField: 'text',
valueField: 'value',
title: 'Left'
},{
width: 250,
height: 200,
store: [['10','Ten']],
tbar:[{
text: 'clear',
handler:function(){
isForm.getForm().findField('itemselector').reset();
}
}],
title: 'Right'
}],
listeners: {
render: function(iSelector){
iSelector.fromMultiselect.fs.header.update(this.initialConfig.multiselects[0].title);
iSelector.toMultiselect.fs.header.update(this.initialConfig.multiselects[1].title);
}
}
}],
buttons: [{
text: 'Save',
handler: function(){
if(isForm.getForm().isValid()){
Ext.Msg.alert('Submitted Values', 'The following will be sent to the server: <br />'+
isForm.getForm().getValues(true));
}
}
}]
});
});
精彩评论