標籤: | 分類:extjs |
- 面板控件panel應用
-
new Ext.Panel({ -
title:'面板頭部(header)', -
tbar : ['頂端工具欄(top toolbars)'], -
bbar : ['底端工具欄(bottom toolbars)'], -
height:200, -
width:300, -
frame:true, -
applyTo :'panel', -
bodyStyle:'background-color:#FFFFFF', -
html:'<div>面板體(body)</div>', -
tools : [ -
{id:'toggle'}, -
{id:'close'}, -
{id:'maximize'} -
], -
buttons:[ -
new Ext.Button({ -
text:'面板底部(footer)' -
}) -
] -
}) -
-
- 面板panel加載遠程頁面
-
var panel = new Ext.Panel({ -
title:'面板加載遠程頁面', -
height:150,//設置面板的高度 -
width:250,//設置面板的寬度 -
frame:true,//渲染面板 -
autoScroll : true,//自動顯示滾動條 -
collapsible : true,//允許展開和收縮 -
applyTo :'panel', -
autoLoad :'page1.html',//自動加載面板體的默認連接 -
bodyStyle:'background-color:#FFFFFF'//設置面板體的背景色 -
}) -
- 面板panel加載本地頁面
-
var panel = new Ext.Panel({ -
title:'面板加載本地資源', -
height:150,//設置面板的高度 -
width:250,//設置面板的寬度 -
frame:true,//渲染面板 -
collapsible : true,//允許展開和收縮 -
autoScroll : true,//自動顯示滾動條 -
autoHeight : false,//使用固定高度 -
//autoHeight : true,//使用自動高度 -
applyTo :'panel', -
contentEl :'localElement',//加載本地資源 -
bodyStyle:'background-color:#FFFFFF'//設置面板體的背景色 -
}) -
本地資源 -
<table border=1 id='localElement'> -
<tr><th colspan=2>本地資源---員工列表</th></tr> -
<tr> -
<th width = 60>序號</th><th width = 80>姓名</th> -
<tr> -
<tr><td>1</td><td>張三</td></tr> -
<tr><td>2</td><td>李四</td></tr> -
<tr><td>3</td><td>王五</td></tr> -
<tr><td>4</td><td>趙六</td></tr> -
<tr><td>5</td><td>陳七</td></tr> -
<tr><td>6</td><td>楊八</td></tr> -
<tr><td>7</td><td>劉九</td></tr> -
</table> -
-
- 使用html配置項定義面板panel內容
-
var htmlArray = [ -
'<table border=1>', -
'<tr><td colspan=2>員工列表</td></tr>', -
'<tr><th width = 60>序號</th><th width = 80>姓名</th><tr>', -
'<tr><td>1</td><td>張三</td></tr>', -
'<tr><td>2</td><td>李四</td></tr>', -
'<tr><td>3</td><td>王五</td></tr>', -
'<tr><td>4</td><td>趙六</td></tr>', -
'<tr><td>5</td><td>陳七</td></tr>', -
'<tr><td>6</td><td>楊八</td></tr>', -
'<tr><td>7</td><td>劉九</td></tr>', -
'</table>' -
]; -
var panel = new Ext.Panel({ -
title:'使用html配置項自定義面板內容', -
height:150,//設置面板的高度 -
width:250,//設置面板的寬度 -
frame:true,//渲染面板 -
collapsible : true,//允許展開和收縮 -
autoScroll : true,//自動顯示滾動條 -
applyTo :'panel', -
html:htmlArray.join(''), -
bodyStyle:'background-color:#FFFFFF'//設置面板體的背景色 -
}) -
-
- 使用items添加panel內容
-
var panel = new Ext.Panel({ -
header : true, -
title:'日曆', -
frame:true,//渲染面板 -
collapsible : true,//允許展開和收縮 -
autoHeight : true,//自動高度 -
width : 189,//固定寬度 -
applyTo :'panel', -
items: new Ext.DatePicker()//向面板中添加一個日期組件 -
}) -
-
-
- 面板panel嵌套的使用
-
-
var panel = new Ext.Panel({ -
header : true, -
title:'使用items進行面板嵌套', -
frame:true,//渲染面板 -
collapsible : true,//允許展開和收縮 -
height : 200, -
width : 250, -
applyTo :'panel', -
defaults : {//設置默認屬性 -
bodyStyle:'background-color:#FFFFFF',//設置面板體的背景色 -
height : 80,//子面板高度爲80 -
collapsible : true,//允許展開和收縮 -
autoScroll : true//自動顯示滾動條 -
}, -
items: [ -
new Ext.Panel({ -
title : '嵌套面板一', -
contentEl : 'localElement'//加載本地資源 -
}), -
new Ext.Panel({ -
title : '嵌套面板二', -
autoLoad : 'page1.html'//加載遠程頁面 -
}) -
] -
}) -
- FitLayout佈局panel
-
-
var panel = new Ext.Panel({ -
layout : 'fit', -
title:'Ext.layout.FitLayout佈局示例', -
frame:true,//渲染面板 -
height : 150, -
width : 250, -
applyTo :'panel', -
defaults : {//設置默認屬性 -
bodyStyle:'background-color:#FFFFFF'//設置面板體的背景色 -
}, -
//面板items配置項默認的xtype類型爲panel, -
//該默認值可以通過defaultType配置項進行更改 -
items: [ -
{ -
title : '嵌套面板一', -
html : '面板一' -
}, -
{ -
title : '嵌套面板二', -
html : '面板二' -
} -
] -
}) -
-
- layout.Accordion佈局panel
-
var panel = new Ext.Panel({ -
layout : 'accordion', -
layoutConfig : { -
activeOnTop : true,//設置打開的子面板置頂 -
fill : true,//子面板充滿父面板的剩餘空間 -
hideCollapseTool: false,//顯示“展開收縮”按鈕 -
titleCollapse : true,//允許通過點擊子面板的標題來展開或收縮面板 -
animate:true//使用動畫效果 -
}, -
title:'Ext.layout.Accordion佈局示例', -
frame:true,//渲染面板 -
height : 150, -
width : 250, -
applyTo :'panel', -
defaults : {//設置默認屬性 -
bodyStyle:'background-color:#FFFFFF;padding:15px'//設置面板體的背景色 -
}, -
items: [ -
{ -
title : '嵌套面板一', -
html : '說明一' -
}, -
{ -
title : '嵌套面板二', -
html : '說明二' -
} -
, -
{ -
title : '嵌套面板三', -
html : '說明三' -
} -
] -
}) -
-
- layout.CardLayout佈局panel
-
var panel = new Ext.Panel({ -
layout : 'card', -
activeItem : 0,//設置默認顯示第一個子面板 -
title:'Ext.layout.CardLayout佈局示例', -
frame:true,//渲染面板 -
height : 150, -
width : 250, -
applyTo :'panel', -
defaults : {//設置默認屬性 -
bodyStyle:'background-color:#FFFFFF;padding:15px'//設置面板體的背景色 -
}, -
items: [ -
{ -
title : '嵌套面板一', -
html : '說明一', -
id : 'p1' -
}, -
{ -
title : '嵌套面板二', -
html : '說明二', -
id : 'p2' -
} -
, -
{ -
title : '嵌套面板三', -
html : '說明三', -
id : 'p3' -
} -
], -
buttons:[ -
{ -
text : '上一頁', -
handler : changePage -
}, -
{ -
text : '下一頁', -
handler : changePage -
} -
] -
}) -
//切換子面板 -
function changePage(btn){ -
var index = Number(panel.layout.activeItem.id.substring(1)); -
if(btn.text == '上一頁'){ -
index -= 1; -
if(index < 1){ -
index = 1; -
} -
}else{ -
index += 1; -
if(index > 3){ -
index = 3; -
} -
} -
panel.layout.setActiveItem('p'+index); -
} -
-
- layout.AnchorLayout佈局panel
-
var panel = new Ext.Panel({ -
layout : 'anchor', -
title:'Ext.layout.AnchorLayout佈局示例', -
frame:false,//渲染面板 -
height : 150, -
width : 300, -
applyTo :'panel', -
defaults : {//設置默認屬性 -
bodyStyle:'background-color:#FFFFFF;padding:15px'//設置面板體的背景色 -
}, -
items: [ -
{ -
anchor : '50% 50%',//設置子面板的寬高爲父面板的50% -
title : '子面板' -
} -
] -
}) -
或者: -
items: [ -
{ -
anchor : '-10 -10',//設置子面板的寬高偏移父面板10像素 -
title : '子面板' -
} -
] -
-
或者: -
items: [ -
{ -
anchor : 'r b',//相對於父容器的右邊和底邊的差值進行定位 -
width : 200, -
height : 100, -
title : '子面板' -
} -
] -
-
或者: -
items: [ -
{ -
x : '10%',//橫座標爲距父容器寬度10%的位置 -
y : 10,//縱座標爲距父容器上邊緣10像素的位置 -
width : 100, -
height : 50, -
title : '子面板一' -
}, -
{ -
x : 90,//橫座標爲距父容器左邊緣90像素的位置 -
y : 70,//縱座標爲距父容器上邊緣70像素的位置 -
width : 100, -
height : 50, -
title : '子面板二' -
} -
] -
- layout.FormLayout佈局panel
-
var panel = new Ext.Panel({ -
title:'Ext.layout.FormLayout佈局示例', -
layout : 'form', -
labelSeparator : ':',//在容器中指定分隔符 -
frame:true,//渲染面板 -
height : 110, -
width : 300, -
applyTo :'panel', -
defaultType: 'textfield',//指定容器子元素默認的xtype類型爲textfield -
defaults : {//設置默認屬性 -
msgTarget: 'side'//指定默認的錯誤信息提示方式 -
}, -
items: [ -
{ -
fieldLabel:'用戶名', -
allowBlank : false -
}, -
{ -
fieldLabel:'密碼', -
allowBlank : false -
} -
] -
}) -
- layout.ColumnLayout佈局panel
-
var panel = new Ext.Panel({ -
title:'Ext.layout.ColumnLayout佈局示例', -
layout : 'column', -
frame:true,//渲染面板 -
height : 150, -
width : 250, -
applyTo :'panel', -
defaults : {//設置默認屬性 -
bodyStyle:'background-color:#FFFFFF;',//設置面板體的背景色 -
frame : true -
}, -
items: [ -
{ -
title:'子面板一', -
width:100,//指定列寬爲100像素 -
height : 100 -
}, -
{ -
title:'子面板二', -
width:100,//指定列寬爲100像素 -
height : 100 -
} -
] -
}) -
-
或者: -
items: [ -
{ -
title:'子面板一', -
columnWidth:.3,//指定列寬爲容器寬度的30% -
height : 100 -
}, -
{ -
title:'子面板二', -
columnWidth:.7,//指定列寬爲容器寬度的70% -
height : 100 -
} -
] -
-
或者: -
items: [ -
{ -
title:'子面板一', -
width : 100,//指定列寬爲100像素 -
height : 100 -
}, -
{ -
title:'子面板二', -
width : 100, -
columnWidth:.3,//指定列寬爲容器剩餘寬度的30% -
height : 100 -
}, -
{ -
title:'子面板三', -
columnWidth:.7,//指定列寬爲容器剩餘寬度的70% -
height : 100 -
} -
] -
-
- layout.TableLayout佈局panel
-
var panel = new Ext.Panel({ -
title:'Ext.layout.TableLayout佈局示例', -
layout : 'table', -
layoutConfig : { -
columns : 4 //設置表格佈局默認列數爲4列 -
}, -
frame:true,//渲染面板 -
height : 150, -
applyTo :'panel', -
defaults : {//設置默認屬性 -
bodyStyle:'background-color:#FFFFFF;',//設置面板體的背景色 -
frame : true, -
height : 50 -
}, -
items: [ -
{ -
title:'子面板一', -
colspan : 3//設置跨列 -
}, -
{ -
title:'子面板二', -
rowspan : 2,//設置跨行 -
height : 100 -
}, -
{title:'子面板三'}, -
{title:'子面板四'}, -
{title:'子面板五'} -
] -
}) -
-
- layout.BorderLayout佈局panel
-
var panel = new Ext.Panel({ -
title : 'Ext.layout.BorderLayout佈局示例', -
layout:'border',//表格佈局 -
height : 250, -
width : 400, -
applyTo : 'panel', -
items: [ -
{ -
title: 'north Panel', -
html : '上邊', -
region: 'north',//指定子面板所在區域爲north -
height: 50 -
}, -
{ -
title: 'South Panel', -
html : '下邊', -
region: 'south',//指定子面板所在區域爲south -
height: 50 -
},{ -
title: 'West Panel', -
html : '左邊', -
region:'west',//指定子面板所在區域爲west -
width: 100 -
},{ -
title: 'east Panel', -
html : '右邊', -
region:'east',//指定子面板所在區域爲east -
width: 100 -
},{ -
title: 'Main Content', -
html : '中間', -
region:'center'//指定子面板所在區域爲center -
}] -
}); -
- Ext.Viewport佈局示例
-
new Ext.Viewport({ -
title : 'Ext.Viewport示例', -
layout:'border',//表格佈局 -
items: [ -
{ -
title: 'north Panel', -
html : '上邊', -
region: 'north',//指定子面板所在區域爲north -
height: 100 -
},{ -
title: 'West Panel', -
html : '左邊', -
region:'west',//指定子面板所在區域爲west -
width: 150 -
},{ -
title: 'Main Content', -
html : '中間', -
region:'center'//指定子面板所在區域爲center -
}] -
}); -
-
-
- Ext.TabPanel
標籤頁示例 -
var tabPanel = new Ext.TabPanel({ -
height : 150, -
width : 300, -
activeTab : 0,//默認激活第一個tab頁 -
animScroll : true,//使用動畫滾動效果 -
enableTabScroll : true,//tab標籤超寬時自動出現滾動按鈕 -
applyTo : 'panel', -
items: [ -
{title: 'tab標籤頁1',html : 'tab標籤頁1內容'}, -
{title: 'tab標籤頁2',html : 'tab標籤頁2內容'}, -
{title: 'tab標籤頁3',html : 'tab標籤頁3內容'}, -
{title: 'tab標籤頁4',html : 'tab標籤頁4內容'}, -
{title: 'tab標籤頁5',html : 'tab標籤頁5內容'} -
] -
}); -
-
- Ext.TabPanel(轉換div)示例
-
-
<mce:script type="text/javascript"><!-- -
Ext.onReady(function(){ -
Ext.BLANK_IMAGE_URL = '../../extjs2.0/resources/images/default/s.gif'; -
var tabPanel = new Ext.TabPanel({ -
height : 50, -
width : 300, -
autoTabs : true,//自動掃描頁面中的div然後將其轉換爲標籤頁 -
deferredRender : false,//不進行延時渲染 -
activeTab : 0,//默認激活第一個tab頁 -
animScroll : true,//使用動畫滾動效果 -
enableTabScroll : true,//tab標籤超寬時自動出現滾動按鈕 -
applyTo : 'panel' -
}); -
}); -
- //
--></mce:script> -
</HEAD> -
<BODY> -
<table width = 100%> -
<tr><td> <td></tr> -
<tr><td width=100></td><td> -
<div id='panel'> -
<div class='x-tab' title='tab標籤頁1'>tab標籤頁1內容</div> -
<div class='x-tab' title='tab標籤頁2'>tab標籤頁2內容</div> -
<div class='x-tab' title='tab標籤頁3'>tab標籤頁3內容</div> -
<div class='x-tab' title='tab標籤頁4'>tab標籤頁4內容</div> -
<div class='x-tab' title='tab標籤頁5'>tab標籤頁5內容</div> -
</div> -
<div class='x-tab' title='tab標籤頁6'>tab標籤頁6內容</div> -
<td></tr> -
</table> -
</BODY> - </HTML>
-
-
- Ext.TabPanel示例(動態添加tab頁)
-
var tabPanel = new Ext.TabPanel({ -
height : 150, -
width : 300, -
activeTab : 0,//默認激活第一個tab頁 -
animScroll : true,//使用動畫滾動效果 -
enableTabScroll : true,//tab標籤超寬時自動出現滾動按鈕 -
applyTo : 'panel', -
resizeTabs : true, -
tabMargin : 50, -
tabWidth : 100, -
items : [ -
{title: 'tab標籤頁1',html : 'tab標籤頁1內容'} -
], -
buttons : [ -
{ -
text : '添加標籤頁', -
handler : addTabPage -
} -
] -
}); -
function addTabPage(){ -
var index = tabPanel.items.length + 1; -
var tabPage = tabPanel.add({//動態添加tab頁 -
title: 'tab標籤頁'+index, -
html : 'tab標籤頁'+index+'內容', -
closable : true//允許關閉 -
}) -
tabPanel.setActiveTab(tabPage);//設置當前tab頁 -
} -
-
- 佈局嵌套實現表單橫排
-
-
var form = new Ext.form.FormPanel({ -
title:'通過佈局嵌套實現表單橫排', -
labelSeparator :':',//分隔符 -
labelWidth : 50,//標籤寬度 -
bodyStyle:'padding:5 5 5 5',//表單邊距 -
frame : false, -
height:150, -
width:250, -
applyTo :'form', -
items:[ -
{ -
xtype : 'panel', -
layout : 'column',//嵌套列布局 -
border : false,//不顯示邊框 -
defaults : {//應用到每一個子元素上的配置 -
border : false,//不顯示邊框 -
layout : 'form',//在列布局中嵌套form佈局 -
columnWidth : .5//列寬 -
}, -
items : [ -
{ -
labelSeparator :':',//分隔符 -
items : { -
xtype : 'radio', -
name : 'sex',//名字相同的單選框會作爲一組 -
fieldLabel:'性別', -
boxLabel : '男' -
} -
}, -
{ -
items : { -
xtype : 'radio', -
name : 'sex',//名字相同的單選框會作爲一組 -
hideLabel:true,//橫排後隱藏標籤 -
boxLabel : '女' -
} -
} -
] -
}, -
{ -
xtype : 'panel', -
layout : 'column',//嵌套列布局 -
border : false,//不顯示邊框 -
defaults : {//應用到每一個子元素上的配置 -
border : false,//不顯示邊框 -
layout : 'form',//在列布局中嵌套form佈局 -
columnWidth : .5//列寬 -
}, -
items : [ -
{ -
labelSeparator :':',//分隔符 -
items : { -
xtype : 'checkbox', -
name : 'swim', -
fieldLabel:'愛好', -
boxLabel : '游泳' -
} -
}, -
{ -
items : { -
xtype : 'checkbox', -
name : 'walk', -
hideLabel:true,//橫排後隱藏標籤 -
boxLabel : '散步' -
} -
} -
] -
}