I've been playing with this for hours and cannot get it to work.
I am trying to add items to a toolbar I have in my view.
I know the proxy is working from the server because I am printing results to console successfully.
please assist... I've been looking in documentation and cant see to find result
Use method addDocked of panel instead method add of dockedItems. (example)
function addToolbar() {
this.up('panel').addDocked({
xtype: 'toolbar',
dock: 'top',
items: [{
text: 'user 1'
}, {
text: 'user 2'
}]
});
};
var filterPanel = Ext.create('Ext.panel.Panel', {
width: 300,
heigth: 300,
title: 'Example',
items: [{
xtype: 'button',
text: 'add toolbar',
handler: addToolbar
}],
dockedItems: [{
xtype: 'toolbar',
dock: 'left',
items: [{
text: 'user 1'
}, {
text: 'user 2'
}]
}],
renderTo: Ext.getBody()
});
For adding new button to existing toolbar in your example use:
view.down('toolbar').add({ text: 'user X' });
I not sure, do you want add new toolbar with buttons, or just want to add new buttons to exist toolbar? This example add new toolbars, as you try to do in your code.
Try something like:
dockedItems: [
xtype: "toolbar",
reference: "myMenu",
items: [...]
]
Then:
this.lookupReference("myMenu").add({text: "new button"});
Related
I am currently working on ExtJs and I am stuck at a place where I want to iterate through all components and find the parent tab of each component.
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.create('Ext.tab.Panel', {
width: 300,
height: 200,
activeTab: 0,
items: [
{
title: 'Tab 1',
bodyPadding: 10,
items : [{
xtype: 'fieldset',
itemId: 'fieldsetId',
items: [{
xtype: 'checkbox',
fieldLabel: 'Check 1'
},{
xtype: 'checkbox',
fieldLabel: 'Check 2'
},{
fieldLabel: 'Combo 1',
xtype: 'combobox',
store: ['value1','value2','value3']
}]
},
{
xtype: 'button',
text: 'Reset',
}]
},
{
title: 'Tab 2',
html : 'Another one',
items: [{
xtype: 'button',
text: 'Test',
}]
}
],
renderTo : Ext.getBody()
});
}
});
In above code, when I iterate through all components and log name of the parent tab whether it is Tab 1 or Tab 2
Whenever you are iterating through all the components, just do
field.up().up()
where field is the component of your tab and above statement will return you the parent tabpanel and so with
field.up().up().title
will return you "Tab 1"
In the same way for tab 2 components it will be
field.up() only.
If you have only one loop or something to go through all components then you can put a condition that
if(field.up()) returns you the panel then read it\'s title
else do field.up().up() and then read the title.
I hope this solves you issue.
You can use , field.up('tabPanel') to get the reference of the tabPanel, and then from the reference you can get name,title for the tabPanel
I have a fieldset defined on my page. Now I want to enable or disable this field set on button click event. But it is not working properly. Below is the code I have written:
To Disable:
this.mySettings.query('[name="fieldsetName"]').forEach(function (field) {
field.disable();
});
To Enable:
this.mySettings.query('[name="fieldsetName"]').forEach(function (field) {
field.enable();
});
Issue-1 : When I disable fieldset, it seems to be disabled visually. But still I can access controls inside it.
Issue-2 : Once it is disabled, I cannot re-enable it.
I need a working sample with these two issues resolved.
Currently I am using version 4.2 of ExtJs
You should call the setDisabled function on the fieldset. It will disable all containing components.
fieldset.setDisabled(true);
// the fieldset and all inner components are disabled
fieldset.setDisabled(false);
// the fieldset and all inner components are enabled
See the Sencha ExtJs 4.2.0 documentation and
the following minimal working example can be found on Sencha Fiddle.
Ext.create('Ext.panel.Panel',{
items: [{
xtype: 'fieldset',
itemId: 'fieldsetId',
items: [{
xtype: 'checkbox',
fieldLabel: 'Check 1'
},{
xtype: 'checkbox',
fieldLabel: 'Check 2'
},{
fieldLabel: 'Combo 1',
xtype: 'combobox',
store: ['value1','value2','value3']
}]
}, {
xtype: 'button',
text: 'Disable fieldset',
handler: function (button) {
var fieldset = Ext.ComponentQuery.query('panel > #fieldsetId')[0];
var toggle = !fieldset.isDisabled();
var text = (toggle ? 'Enable' : 'Disable') + ' fieldset';
fieldset.setDisabled(toggle);
button.setText(text);
}
}],
renderTo: Ext.getBody()
});
Paste this into a Sencha fiddle and hit Run:
Ext.application({
name : 'Fiddle',
launch : function() {
Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
Ext.create('Ext.window.Window', {
height: '100%',
width: '100%',
autoShow:true,
bodyPadding: 25,
title:'win',
items: [{
xtype: 'fieldset',
items: [{
xtype: 'checkbox',
fieldLabel: 'field1'
},{
xtype: 'checkbox',
fieldLabel: 'field2'
},{
fieldLabel: 'field3',
xtype: 'combo',
store: ['asdf','zzasdf','dfdf']
}]
}, {
xtype: 'button',
text: 'Enable/Disable entire fieldset',
handler: function(btn){
var fset = btn.up('window').down('fieldset');
fset.setDisabled(!fset.disabled);
}
}, {
margin: '0 0 0 10',
xtype: 'button',
text: 'Enable/Disable each field in fieldset individually',
handler: function(btn){
var fset = btn.up('window').down('fieldset');
fset.items.each(function(i){
i.setDisabled(!i.disabled);
});
}
}]
});
}
});
Is it possible to position some of my items in my panel to the left, and the last items all the way to the right? So that there is an empty space in the middle. Right now I am using hbox layout, and put an empty container in the middle and flex it like this:
items: [{
xtype: 'container',
layout: 'hbox',
items: [{
xtype: 'label',
text: 'Filter on vehicle'
},{
xtype:'textfield'
},{
xtype: 'button',
text: '...'
},{
xtype: 'container',
flex:1
},{
xtype: 'button',
text: 'New'
},{
xtype:'button',
text: 'Edit'
},{
xtype: 'button',
text: 'Delete'
}]
}]
Any better way to do this?
Don't know if it is a better solution or not.But DOM wise it will be lighter.
We can use tbfill xtype instead of inserting a container.
{
xtype: 'container',
layout: 'border',
items: [{
xtype: 'label',
text: 'Filter on vehicle',
},{
xtype:'textfield',
},{
xtype: 'button',
text: '...',
},
{
xtype:'tbfill'
},{
xtype: 'button',
text: 'New',
},{
xtype:'button',
text: 'Edit',
},{
xtype: 'button',
text: 'Delete',
}],
}
Working Example
If you want to use elements like button, textfield, label, combobox... You can use Ext.toolbar.Toolbar xtype: toolbar. So if you need to put items to the right you can easy do this with '->', also you can use '|' to put vertical separator to the tollbar.
Ext.create('Ext.container.Container', {
renderTo: Ext.getBody(),
items: [
{
xtype: 'toolbar',
layout: 'hbox',
items: [
{
xtype: 'label',
text: 'Filter on vehicle'
},
{
xtype: 'textfield'
},
{
xtype: 'button',
text: '...'
},
{
xtype: 'button',
text: 'New'
},
'->',
{
xtype: 'button',
text: 'Edit'
},
{
xtype: 'button',
text: 'Delete'
}
]
}
]
});
What you're doing is fine, and arguably the best solution with 1 minor suggestion. Use 'component' instead of 'container' as that will be slightly lighter.
The previous answers of 'tbfill' and '->' are actually the same thing as what you're doing. '->' is a shorthand for 'tbfill' and 'tbfill' is literally a flex:1 component.
All 3 solutions should work fine but I like using a flex:1 component because using tbfill depends on knowing an implementation detail of toolbar, namely that is uses hbox. Sencha is free to change how toolbar and tfill work in a future release, at which point your code (if it uses tbfill) is broken.
I have an ExtJS 4.2.1 accordion layout with three panels.
When the app is first launched, the first panel is open and the 2nd/3rd are closed.
I can open and close the 2nd and 3rd, but I can never close the first panel.
Ext.define('MyAccordion', {
extend: 'Ext.container.Container',
alias: 'widget.myAccordion',
padding: 0,
margin: 0,
width: 200,
layout: {
type: 'accordion',
align: 'stretch',
animate: true,
hideCollapseTool: true
},
items: [{
xtype: 'panel',
title: 'Test Volumes',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'label',
text: 'volume one'
},{
xtype: 'label',
text: 'volume two'
},{
xtype: 'label',
text: 'volume three'
}]
}, {
xtype: 'panel',
title: 'Production Volumes',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'label',
text: 'volume one'
},{
xtype: 'label',
text: 'volume two'
},{
xtype: 'label',
text: 'volume three'
}]
}, {
xtype: 'panel',
title: 'Extra Volumes',
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'label',
text: 'volume one'
},{
xtype: 'label',
text: 'volume two'
},{
xtype: 'label',
text: 'volume three'
}]
}]
});
In the following code leveraged from the 4.2.1 examples layout browser example, if the first thing you do after launching the app is click the first header, is does close, but then re-open it and it never closes again:
Ext.onReady(function() {
Ext.create('Ext.container.Viewport', {
renderTo: Ext.getBody(),
items: [{
xtype: 'panel',
title: 'Accordion Layout',
layout: 'accordion',
defaults: {bodyStyle: 'padding:15px'},
items: [{
title: 'Introduction',
tools: [{type:'gear'},{type:'refresh'}],
html: '<p>Here is some accordion content. Click on one of the other bars below for more.</p>'
},{
title: 'Basic Content',
html: '<br /><br /><p>More content. Open the third panel for a customized look and feel example.</p>',
items: {
xtype: 'button',
text: 'Show Next Panel',
handler: function(){
Ext.getCmp('acc-custom').expand(true);
}
}
},{
id: 'acc-custom',
title: 'Custom Panel Look and Feel',
cls: 'custom-accordion', // look in layout-browser.css to see the CSS rules for this class
html: '<p>Here is an example of how easy it is to completely customize the look and feel of an individual panel simply by adding a CSS class in the config.</p>'
}]
}]
});
});
Even more strange, if I do show the collapse/expand tool, the tool for the first panel stops working.
Amazing but true, but this happens because the accordion layout container does not have a height set.
Because I can't have a fixed height, this fixes the issue: flex: 1
But this seems really strange, because why should not having a height (or flex, etc) break closing the first container? Just seems weird.
An easy solution would be to add _isLayoutRoot: true to panel with accordion layout.
Ext.define('myAccordion',{
extend: 'Ext.Panel',
alias: 'widget.myAccordion',
layout: 'accordion',
_isLayoutRoot: true,
items: myItems
});
Example: http://jsfiddle.net/38mx9hs9/1/
Also it seems that this issue is fixed in 4.2.2:
https://www.sencha.com/forum/showthread.php?267163-4-2-1-Accordion-Layout-in-Panel&p=1169533#post1169533
I have the following grid here:
Ext.define('AM.view.user.List', {
extend: 'Ext.grid.Panel',
alias: 'widget.userlist',
title: 'All Users',
store: 'Users',
initComponent: function () {
this.columns = [{
header: 'Name',
dataIndex: 'name',
flex: 4
}, {
header: 'User ID',
dataIndex: 'user_id',
flex: 1
}, {
header: 'Address',
dataIndex: 'address',
flex: 3
}, {
header: 'Age',
dataIndex: 'agee',
flex: 5
}];
this.callParent(arguments);
}
});
Can a toolbar be added to the bottom of this grid or can they only be added to panels?
Also, how can I place normal text in a toolbar rather than a button?
Yes a grid panel inherits Ext.grid.Panel, you should be able to add:
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
items: [{
xtype: 'button',
text: 'Left Button'
}, {
xtype: 'tbfill'
}, {
xtype: 'button',
text: 'Right Button'
}]
}]
Any component that has Docked layout can have toolbars docked. Since Ext.grid.Panel extends Ext.panel.Panel, you can dock to it. See the bbar config: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.panel.Panel-cfg-bbar
You can add text items to your toolbar by adding this to the toolbar's items:
{ xtype: 'tbtext', text: 'My Text' }
Docs for this here: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.toolbar.TextItem
Alternately you can also add button using 'bbar[...]' which is equivalent to
dockedItems: [{
xtype: 'toolbar',
dock: 'bottom',
items: [
{ xtype: 'button', text: 'Button 1' }
]
}]
this allows you to add buttons at the bottom of your gridpanel all other button properties are allowed to use.
sample code is here:
bbar: [
{ xtype: 'button', text: 'Button 1' },
{ xtype: 'button', text: 'Button 2' }
]
for more details you can refer the doc: http://docs.sencha.com/extjs/6.0/6.0.1-classic/#!/api/Ext.panel.Panel-cfg-bbar