㈠ extjs的panel組件怎麼使用
//html代碼
<div id="container">
</div>
//js代碼
var p = new Ext.Panel({
title: 'My Panel',//標題
collapsible:true,//右上角上的那個收縮按鈕,設為false則不顯示
renderTo: 'container',//這個panel顯示在html中id為container的層中
width:400,
height:200,
html: "<p>我是內容,我包含的html可以被執行!</p>"//panel主體中的內容,可以執行html代碼
});
因為panel組件的子類組件包括TabPanel,GridPanel,FormPanel,TreePanel組件,所以非常有必要介紹Panel組件的配置參數和相關的屬性、方法。
//配置參數(只列舉部分常用參數)
1.autoLoad:有效的url字元串,把那個url中的body中的數據載入顯示,但是可能沒有樣式和js控制,只是html數據
2.autoScroll:設為true則內容溢出的時候產生滾動條,默認為false
3.autoShow:設為true顯示設為"x-hidden"的元素,很有必要,默認為false
4.bbar:底部條,顯示在主體內,//代碼:bbar:[{text:'底部工具欄bottomToolbar'}],
5.tbar:頂部條,顯示在主體內,//代碼:tbar:[{text:'頂部工具欄topToolbar'}],
6.buttons:按鈕集合,自動添加到footer中(footer參數,顯示在主體外)//代碼:buttons:[{text:"按鈕位於footer"}]
7.buttonAlign:footer中按鈕的位置,枚舉值為:"left","right","center",默認為right
8.collapsible:設為true,顯示右上角的收縮按鈕,默認為false
9.draggable:true則可拖動,但需要你提供操作過程,默認為false
10.html:主體的內容
11.id:id值,通過id可以找到這個組件,建議一般加上這個id值
12.width:寬度
13.height:高度
13.title:標題
14.titleCollapse:設為true,則點擊標題欄的任何地方都能收縮,默認為false.
15.applyTo:(id)呈現在哪個html元素裡面
16.contentEl:(id)呈現哪個html元素裡面,把el內的內容呈現
17.renderTo:(id)呈現在哪個html元素裡面
//關於這三個參數的區別(個人認為:applyTo和RenderTo強調to到html元素中,contentEl則是html元素到ext組件中去):
英文如下(本人英語poor,不敢亂翻譯):
contentEl - This config option is used to take existing content and place it in the body of a new panel. It is not going to be the actual panel itself. (It will actually the innerHTML of the el and use it for the body). You should add either the x-hidden or the x-hide-display CSS class to prevent a brief flicker of the content before it is rendered to the panel.
applyTo - This config option allows you to use pre-defined markup to create an entire Panel. By entire, I mean you can include the header, tbar, body, footer, etc. These elements must be in the correct order/hierarchy. Any components which are not found and need to be created will be autogenerated.
renderTo - This config option allows you to render a Panel as its created. This would be the same as saying myPanel.render(ELEMENT_TO_RENDER_TO);
哪位大人幫忙翻譯下...
考慮到入門,方法事件會在以後的文章中以實例穿插。
1.可拖動的panel實例
下面我們做個可拖動panel例子來熟悉下panel這個最基本的組件.
//html代碼
..無..
//下面創建一個允許拖動的panel,但是拖動的結果不能保存
var p=new Ext.Panel({
title: 'Drag me',
x: 100,
y: 100,
renderTo: Ext.getBody(),//x,y,renderTo:Ext.getBody()初始化panel的位置
floating: true,//true
frame: true,//圓角邊框
width: 400,
height: 200,
draggable:true
}).show();//在這里也可以不show()
但是還不能拖到其他的地方,我們需要改寫draggable:
draggable: {
insertProxy: false,//拖動時不虛線顯示原始位置
onDrag : function(e){
var pel = this.proxy.getEl();
this.x = pel.getLeft(true);
this.y = pel.getTop(true);//獲取拖動時panel的坐標
},
endDrag :
function(e){
this.panel.setPosition(this.x, this.y);//移動到最終位置
}
}
實現了可保存的拖動
拖動的時候陰影還在原位置,我們再在draggable中的onDrag事件中添加代碼:
var s = this.panel.getEl().shadow;
if (s) {
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
//shadow的realign方法的四個參數,改變shadow的位置大小屬性
最後這個可拖動的panel的代碼為:
var p=new Ext.Panel({
title: 'Drag me',
x: 100,
y: 100,
renderTo: Ext.getBody(),
floating: true,
frame: true,
width: 400,
height: 200,
draggable: {
insertProxy: false,
onDrag :
function(e){
var pel = this.proxy.getEl();
this.x = pel.getLeft(true);
this.y = pel.getTop(true);
var s = this.panel.getEl().shadow;
if (s) {
s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
}
},
endDrag : function(e){
this.panel.setPosition(this.x, this.y);
}
}
})
//效果圖片我就不貼出來了
2.帶頂部,底部,腳部工具欄的panel
var p=new Ext.Panel({
id:"panel1",
title:"標題",
collapsible:true,
renderTo:"container",
closable:true,
width:400,
height:300,
tbar:[{text:"按鈕1"},{text:"按鈕2"}], //頂部工具欄
bbar:[{text:"按鈕1"},{text:"按鈕2"}], //底部工具欄
html:"內容",
buttons:[{text:"按鈕1"},{text:"按鈕2"}] //footer部工具欄
});
我們已經在各種工具欄上添加了按鈕,但是卻沒有激發事件,下面我們來添加按鈕事件代碼:
tbar:[{text:"按鈕1",handler:function(){Ext.MessageBox.alert("我是按鈕1","我是通過按鈕1激發出來的彈出框!")}},{text:"按鈕2"}],
//改寫tbar,添加handler句柄,點擊頂部工具欄上按鈕1,彈出提示框,效果圖大家想像下,就不貼出來了
當然,一般情況下,我們只要一個工具欄,這里只是為了演示!
3.panel工具欄
//添加下面的代碼到panel配置參數中
tools:[{id:"save"},{id:"help"},{id:"up"},{id:"close",handler:function(){Ext.MessageBox.alert("工具欄按鈕","工具欄上的關閉按鈕時間被激發了")}}],
//id控制按鈕,handler控制相應的事件
//id的枚舉值為:
toggle (collapsable為true時的默認值)
close
minimize
maximize
restore
gear
pin
unpin
right
left
up
down
refresh
minus
plus
help
search
save
print
㈡ extjs中添加10個tabpanel各並帶一個panel怎麼實現
自定義一個formpanel 擴展類, 用數組來存放 每個formpanel的數據
FormClass=Ext.extend(Ext.FormPanel,{
frame:true,
layout:'table',
trackResetOnLoad:false,
layoutConfig:{columns:3},
defaults:{labelAlign:'right',labelWidth:90,frame:false,layout:'form'},
initComponent:function(val_arr){
varthat=this;
this.fields_arr['id']=newExt.form.TextField({name:'id',fieldLabel:'id',value:val_arr['id']});
this.fields_arr['name']=newExt.form.TextField({name:'name',fieldLabel:'name',value:val_arr['name']});
//formpanel的元素和值都用數組包含給不同的數組就展示不同的數據
Ext.apply(this,{
items:[this.fields_arr['id'],this.fields_arr['name']]
});
FormClass.superclass.initComponent.call(this);
},
}
//使用時
formpanel=newFormClass(newarray('id':001,'name':'name1'))
formpanel2=newFormClass(newarray('id':002,'name':'name2'))
㈢ extjs table 文字垂直居中 怎樣使單元格的文字縱向居中
瀏覽器打開開發人員專工作屬F12
.x-grid3-row td, .x-grid3-summary-row td {
line-height: 13px;
vertical-align: middle;
padding-left: 1px;
padding-right: 1px;
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: ignore;
}
㈣ 在ExtJs中,TabPanel中如何布局,讓兩個文本框在一行顯示呢
兩個組件顯示到一行就用布局,從你需要的效果來看,有兩種方法:
1、要用到兩個布內局的結合,分別是容column和form布局;
2、用一種布局加panel代替顯示原來組件的fieldlabel;
我個人比較偏向第一種,代碼如:
...
layout:'column',
items:[
{
columnWidth:.5,
layout:'form',
items:[sexTextFiled] //sex 的組件
},{
columnWidth:.5,
layout:'form',
items:[dateField] //date 的組件
}
]
順便說下為什麼要兩種布局組合,因為column布局的效果不能顯示fieldLabel,只有form布局可以顯示fieldLabel。當然,你要的效果也有其他方法可以實現,希望對LZ有幫助。
㈤ ExtJS如何使panel 的內容居中顯示
試下將panel渲染到某個居中顯示div裡面。
panel加入這個配置項:renderTo:'div1'
HTML相關代碼:<div id="div1" style="margin:0 auto; width:[panel的寬度]"></div>
㈥ 在Extjs中,我想通過點擊一個按鈕,然後在一個TabPanel中加入一個Panel組件,請問怎麼做
var centerPanel = Ext.create('Ext.TabPanel', {
region: 'center',
deferredRender: false,
activeTab: 0,
items: []
})
var ftab = Ext.create('Ext.Panel', {
tpl: new Ext.XTemplate('<iframe style="width: 100%; height: 100%; border: 0;padding:4px 4px 4px 4px;" src="{url}"></iframe>'),
load: function (b) { this.update(this.tpl.apply(b)) }, clear: function () { this.update("") },
title: '首頁',
autoScroll: true
});
ftab.load({ url: '<%=Url.Action("Welcome",new{ controller="Home"}) %>' });
centerPanel.add(ftab);
function trsel(view, record, item, index, e) {
if (record.raw.leaf) {
var tab = centerPanel.getComponent("tab" + record.raw.id); //獲取tab對象
if (!tab) {//如果tab不存在,就創建並添加到中
tab = Ext.create('Ext.Panel', {
tpl: new Ext.XTemplate('<iframe style="width: 100%; height: 100%; border: 0;padding:4px 4px 4px 4px;" src="{url}"></iframe>'),
load: function (b) { this.update(this.tpl.apply(b)) }, clear: function () { this.update("") },
id: "tab" + record.raw.id,
title: record.raw.text,
closable: true,
autoScroll: true
});
tab.load({ url: '/' + record.raw.menu_area + '/' + record.raw.menu_controller + '/' + record.raw.menu_action });
centerPanel.add(tab);
}
centerPanel.setActiveTab(tab); //設置顯示當前面板
}
};
函數是點擊菜單樹時調用的。你自己調整一下,點按鈕時調這個函數就可以。不過網上說用iframe不好,我也想看看有沒有其他的方法
㈦ ExtJS TabPanel獲取組件問題
1一般常用的方法是給新增的panel 設定itemId , 用 容器.getComponent(itemId)來獲取這個組件.(推薦)
vartabs=newExt.TabPanel({
renderTo:document.body,
itemId:"tablpanel1"
height:100
});
tabs.add({
title:'標題1',
itemId:"panel1"
html:'內容1'
});
varnewp=tabs.getComponent("panel1")//newp是新增的記錄
2 給新增的panel 設定Id 用 Ext.body.getCmp(ID)來獲取這個組件. (不推薦)
vartabs=newExt.TabPanel({
renderTo:document.body,
itemId:"tablpanel1"
height:100
});
tabs.add({
title:'標題1',
id:"panel1"
html:'內容1'
});
varnewp=Ext.body.getCmp("panel1")//newp是新增的記錄
3. 設置全局變數為新增的panel 使用時直接用 變數名來引用.(不推薦)
varnewp=newExt.Panel({
title:'標題1',
id:"panel1"
html:'內容1'
});
vartabs=newExt.TabPanel({
renderTo:document.body,
itemId:"tablpanel1"
height:100
});
tabs.add(newp)////newp是新增的記錄
4. 在自定義類中用 屬性名 為新增的panel, 用屬性名來引用 獲取(推薦)
this.newp=newExt.Panel({
title:'標題1',
id:"panel1"
html:'內容1'
});
this.tabs=newExt.TabPanel({
renderTo:document.body,
itemId:"tablpanel1"
height:100
});
this.tabs.add(this.newp);//this.newp是新增的記錄