Rob*_*ter 5 extjs extjs4 extjs3
如何在TabControl中的每个选项卡的标题中添加按钮(工具)?
我只是可以在TabPanel中添加工具,但我想在选项卡中添加.
我也试过这个,但没有成功:
var lTabPanel = Ext.create('Ext.tab.Panel', {
width: 400,
height: 400,
renderTo: document.body,
items: [{
title: 'Home',
html: 'Home',
itemId: 'home'
}, {
title: 'Users',
html: 'Users',
itemId: 'users',
hidden: true
}, {
title : 'Tickets',
html : 'Tickets',
itemId : 'tickets',
tools:[{
type:'gear',
tooltip: 'Options',
handler: function(event, toolEl, panel){
// Some code.
}
}]
}]
});
Run Code Online (Sandbox Code Playgroud)
任何的想法?
谢谢!
Lio*_*han 12
实际上相当艰难.
如果您检查他们的源代码,Ext.tab.Panel
实际上是使用卡片布局,并且对于每个选项卡,他们曾经使用Ext.tab.Tab
选项卡按钮.
然后,如果你检查源代码Ext.tab.Tab
,它实际上是扩展Ext.button.Button
,这只是一个修改过的按钮.
因此,如果您需要添加工具,我担心最好的方法是扩展Ext.tab.Tab
和编写您自己的选项卡按钮.你可能想看看他们是如何创建closeable
的线路按键233的/src/tab/Tab.js
.
(EXT-4.0.2a)
干杯
编辑
所以我们知道Ext.tab.Tab
正在扩展Ext.button.Button
,我们可以利用这个事实,我已经提出了这个解决方案,请在小提琴中查看:http://jsfiddle.net/uBxqY/4/
基本上,我已经扩展Ext.tab.Tab
,并修改了buttonWrapper类,以便添加箭头css.没什么好看的,一切都开箱即用.
此外,我已经覆盖了该onClick
功能,因此当用户单击选项卡本身时,菜单将不会展开.有点脏,但它的工作原理(借来prototype.onClick
的Ext.button.Split
.
工作示例:http://jsfiddle.net/uBxqY/4/,或来源:
Ext.define('Ext.ux.tab.Tab', {
extend: 'Ext.tab.Tab',
alias: 'widget.ux.menutab',
requires: [
//We just need the onClick from Split button
'Ext.button.Split'
],
/**
* Menu align, if you need to hack the menu alignment
*/
menuAlign: 'tl-bl?',
constructor: function() {
this.callParent(arguments);
//Kind of harsh, we need the click action from
//split button instead.
//Or if you preferred, you can always override this
//function and write your own handler.
this.onClick = Ext.button.Split.prototype.onClick;
},
/**
* Hack the default css class and add
* some resonable padding so to make it looks
* great :)
*/
onRender: function() {
this.callParent(arguments);
//We change the button wrap class here! (HACK!)
this.btnWrap.replaceCls('x-tab-arrow x-tab-arrow-right',
'x-btn-split x-btn-split-right')
.setStyle('padding-right', '20px !important');
}
});
Ext.create('Ext.tab.Panel', {
renderTo: Ext.getBody(),
style: 'margin:10px;',
defaults: {
bodyStyle: 'padding:10px;'
},
plain: true,
items: [{
title: 'Split Tab',
//tabConfig is taken up during tab formation
tabConfig: {
//We use our own custom tab!
xtype: 'ux.menutab',
menu: [{
text: 'Menu item 1'
},{
text: 'Menu item 2'
}]
},
html: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
},{
title: 'Normal Tab',
html: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
}]
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10237 次 |
最近记录: |