Extjs单独定义各组件的实例代码


Posted in Javascript onJune 25, 2013

网上看到的一个事例,其中包含了组件的定义拷贝下来供大家参考:

Ext.onReady(function(){ 
var dtCategory=[ 
['all','所有种类'], 
['1','Beverages'], 
['2','Condiments'], 
['3','Confections'], 
['4','Dairy Products'], 
['5','Grains/Cereals'], 
['6','Meat/Poultry '], 
['7','Produce'], 
['8','Seafood'] 
]; 
var stCategory=new Ext.data.SimpleStore({ 
fields:['value','text'], 
data:dtCategory 
}); 
var cbCategory=new Ext.form.ComboBox({ 
id:"cbCategory", 
store:stCategory, 
displayField:"text", 
valueField:"value", 
typeAhead:true, 
mode:"local", 
triggerAction:"all", 
emptyText:"请选择商品种类...", 
editable:false, 
allowBlank:false, 
blankText:"商品种类必须选择", 
autoSelect:true, 
selectOnFoucus:true, 
value:'', 
dfval:'' 
}); 
cbCategory.setValue("all"); 
var tfName=new Ext.form.TextField({ 
id:'tfName' 
}); 
var btnSearch=new Ext.Button({ 
id:'btnSearch', 
iconCls:'btn_search', 
text:'搜索', 
handler:function(){ 
stProduct.load({params:{start:0,limit:10,categoryName:Ext.getCmp("cbCategory").getValue(),productName:Ext.getCmp("tfName").getValue()}}); 
} 
}); 
var btnHelp=new Ext.Button({ 
text:'帮助', 
iconCls:'btn_help' 
}) 
var tb=new Ext.Toolbar({ 
id:'tb', 
items:[ 
'商品种类:', 
cbCategory, 
'-', 
'商品名称:', 
tfName, 
btnSearch, 
'->', 
btnHelp 
] 
}); 
var pnNorth=new Ext.Panel({ 
id:'pnNorth', 
region:'north', 
autoHeight:true, 
items:[ 
tb 
] 
}); 
var url="Default.aspx"; 
var stProduct=new Ext.data.Store({ 
id:"st", 
proxy:new Ext.data.HttpProxy({url:url}), 
reader:new Ext.data.JsonReader({totalProperty:"totalProperty",root:"root",fields:[{name:"ProductID"},{name:"ProductName"},{name:"CategoryName"},{name:'UnitPrice'},{name:'Discontinued'},{name:'QuantityPerUnit'},{name:'CompanyName'}] })//ProductID作为隐藏列,不显示在gridpanel中 
}); 
stProduct.load({params:{start:0,limit:10,categoryName:Ext.getCmp("cbCategory").getValue(),productName:Ext.getCmp("tfName").getValue()}}); 
var cmProduct=new Ext.grid.ColumnModel([ 
new Ext.grid.RowNumberer(), 
{header:"产品名称",dataIndex:"ProductName",sortable:true}, 
{header:"产品种类",dataIndex:"CategoryName",sortable:true}, 
{header:"单价",dataIndex:"UnitPrice",sortable:true}, 
{header:"是否停产",dataIndex:"Discontinued",sortable:true}, 
{header:"规格",dataIndex:"QuantityPerUnit",sortable:true}, 
{header:"供货商",dataIndex:"CompanyName",sortable:true} 
]); 
var pgtbProduct=new Ext.PagingToolbar({ 
id:"pgtbProduct", 
displayInfo:true, 
emptyMsg:"没有数据要显示!", 
displayMsg:"当前为第{0}--{1}条,共{2}条数据", 
store:stProduct, 
pageSize:10 
}); 
var grdProduct=new Ext.grid.GridPanel({ 
id:"grdProduct", 
title:"商品信息", 
cm:cmProduct, 
store:stProduct, 
autoWidth:true, 
selModel:new Ext.grid.RowSelectionModel({single:true}), 
height: screen.availHeight-190, 
frame: true, 
pageSize:20, 
bbar:pgtbProduct, 
//autoExpandColumn:6, 
loadMask:true, 
viewConfig:{ 
forceFit:true 
} 
}); 
var stSupplier = new Ext.data.Store({ 
id: "stSupplier", 
autoLoad:true, 
proxy: new Ext.data.HttpProxy({ url: "ProductInfo.aspx?type=getSupplierInfo" }), 
reader: new Ext.data.JsonReader({ totalProperty: "totalProperty", root: "root", fields: [{ name: "sID" }, { name: "cName"}] }) 
}); 
var pnProduct=new Ext.Panel({ 
id:'pnProduct', 
title:'商品信息', 
autoHeight:true, 
items:[ 
new Ext.Panel({ 
id:'pnProductRowOne', 
border:false, 
bodyStyle:'padding-top:10px;', 
layout:'column', 
items:[ 
new Ext.Panel({ 
columnWidth:.5, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'textfield', 
id:'ProductName', 
name:'ProductName', 
fieldLabel:'商品名称', 
anchor:'95%' 
} 
] 
}), 
new Ext.Panel({ 
columnWidth:.25, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'radio', 
id:'DiscontinuedOneID', 
//hiddenName:'Discontinued', 
name:'Discontinued', 
inputValue:'1', 
fieldLabel:'是否停售', 
boxLabel:'是', 
anchor:'95%' 
} 
] 
}), 
new Ext.Panel({ 
columnWidth:.25, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'radio', 
id:'DiscontinuedTwoID', 
//hiddenName:'Discontinued', 
name:'Discontinued', 
checked:true, 
inputValue:'0', 
boxLabel:'否', 
anchor:'95%' 
} 
] 
}) 
] 
}), 
new Ext.Panel({ 
id:'pnProductRowTwo', 
border:false, 
layout:'column', 
items:[ 
new Ext.Panel({ 
columnWidth:.5, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'textfield', 
id:'QuantityPerUnit', 
name:'QuantityPerUnit', 
fieldLabel:'规格', 
anchor:'95%' 
} 
] 
}), 
new Ext.Panel({ 
columnWidth:.5, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'textfield', 
id:'UnitPrice', 
name:'UnitPrice', 
fieldLabel:'单价', 
anchor:'95%' 
} 
] 
}) 
] 
}), 
new Ext.Panel({ 
id:'pnProductRowThree', 
border:false, 
layout:'column', 
items:[ 
new Ext.Panel({ 
columnWidth:.5, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'textfield', 
id:'UnitsInStock', 
name:'UnitsInStock', 
fieldLabel:'库存量', 
anchor:'95%' 
} 
] 
}) 
, 
new Ext.Panel({ 
columnWidth:.5, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'combo', 
id:'CommpanyName', 
//name:'CommpanyName', 
hiddenName:'SupplierID', 
fieldLabel:'供货商', 
displayField: 'cName', 
valueField: 'sID', 
mode: 'local', 
typeAhead: true, 
triggerAction: "all", 
editable: false, 
allowBlank: false, 
autoSelect: true, 
selectOnFoucus: true, 
store: stSupplier, 
anchor:'95%' 
} 
] 
}) 
] 
}) 
] 
}); 
var pnCategory=new Ext.Panel({ 
id:'pnCategory', 
title:'商品相关种类信息', 
autoHeight:true, 
items:[ 
new Ext.Panel({ 
id:'pnCategoryRowOne', 
border:false, 
bodyStyle:'padding-top:10px;', 
layout:'column', 
items:[ 
new Ext.Panel({ 
columnWidth:.5, 
border:false, 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'textfield', 
id:'CategoryName', 
name:'CategoryName', 
fieldLabel:'商品种类', 
anchor:'95%' 
}, 
{ 
xtype:'textfield', 
id:'Description', 
name:'Description', 
fieldLabel:'商品描述', 
anchor:'95%' 
}, 
{ 
xtype:'hidden', 
id:'CategoryID', 
name:'CategoryID', 
fieldLabel:'种类编号'//这个是隐藏的 
} 
] 
}), 
new Ext.Panel({ 
columnWidth:.5, 
border:false, 
bodyStyle:'padding-left:25px;', 
layout:'form', 
labelWidth:60, 
labelAlign:'right', 
items:[ 
{ 
xtype:'box',// 
id:'CategoryImage', 
width:172, 
height:120, 
autoEl:{ 
tag:'image', 
src:'tempFile/1.png' 
} 
} 
] 
}) 
] 
}) 
] 
}); 
var tpProduct=new Ext.TabPanel({//很多时候我们可能是一个表单放在不同的tab中,为了方便提交和加载数据可以在tabpanel最外层放一个formpanel,但是显示就有问题,这个时候可以通过设置tabpanel高度和deferredRender、layoutOnTabChange两个属性来调整 
id:'tpProduct', 
deferredRender:false,//是否第一次显示就渲染所有tab(默认为true) 
layoutOnTabChange:true, 
//height:300, 
//autoTabs:true, 
activeTab:0, 
border:false, 
items:[ 
pnProduct, 
pnCategory 
] 
}); 
var fpProduct=new Ext.FormPanel({//作为TabPanel的容器 
id:'fpProduct', 
reader: new Ext.data.JsonReader({ 
successProperty: 'success',//后台返回的json中成功与否的字段名称 
root: 'info'//后台返回的json中,数据字段名称 
}, 
[ 
'ProductName', 
//'Discontinued', 
'QuantityPerUnit', 
'UnitPrice', 
'UnitsInStock', 
'CategoryID', 
'CategoryName', 
'Description', 
'SupplierID' 
] 
), 
items:[ 
tpProduct 
] 
}); 
var winProductInfo=new Ext.Window({ 
title:'商品信息', 
width:450, 
height:300, 
layout:'fit', 
closeAction:'hide', 
plain:true,//true则主体背景透明,false则和主体背景有些差别 
collapsible:true,//是否可收缩 
modal:true,//是否为模式窗体 
items:[ 
fpProduct 
], 
buttons:[//窗体按钮 
{ 
text:'提交', 
handler:function(){ 
if(fpProduct.getForm().isValid()){ 
var record=grdProduct.getSelectionModel().getSelected(); 
fpProduct.getForm().submit({ 
method:'post', 
url:'ProductInfo.aspx?type=updateProductInfo&productId='+record.get("ProductID"), 
waitMsg:'数据更新中...', 
success:function(){ 
stProduct.reload(); 
Ext.Msg.alert("系统提示","提交成功!"); 
}, 
failure:function(){ 
Ext.Msg.alert("系统提示","提交失败!"); 
} 
}); 
} 
} 
}, 
{ 
text:'关闭', 
handler:function(){//点击时触发的事件 
winProductInfo.hide(); 
} 
} 
] 
}); 
// Ext.getCmp('tp').on("tabchange",function(tabPanel,tab){ 
// Ext.Msg.alert("系统提示","Tab标题:"+tab.title); 
// }); 
grdProduct.on("rowdblclick",function(grid,rowIndex,e){ 
var row=grid.getStore().getAt(rowIndex).data; 
//Ext.Msg.alert("系统提示","行:"+rowIndex+" 产品ID:"+row.ProductID); 
fpProduct.form.load({//利用load自动填充,注意表单控件字段一定要和json中一致 
url:'ProductInfo.aspx?type=getProductInfo&productId='+row.ProductID, 
waitMsg:'数据加载中...', 
success:function(){ 
//alert("tempFile/"+row.CategoryName+".png"); 
if(row.Discontinued=="是"){ 
Ext.getCmp('DiscontinuedOneID').setValue(true); 
}else{ 
Ext.getCmp('DiscontinuedTwoID').setValue(true); 
} 
Ext.getCmp('CategoryImage').getEl().dom.src="tempFile/"+row.CategoryName+".png"; 
}, 
failure:function(){ 
Ext.Msg.alert("系统提示","数据加载失败!"); 
} 
}); 
winProductInfo.show(); 
}); 
var pnCenter=new Ext.Panel({ 
id:'pnCenter', 
region:'center', 
items:[ 
grdProduct 
] 
}); 
var vp=new Ext.Viewport({ 
id:'vp', 
layout:'border', 
renderTo:Ext.getBody(), 
items:[ 
pnNorth, 
pnCenter 
] 
}); 
});
Javascript 相关文章推荐
JavaScript flash复制库类 Zero Clipboard
Jan 17 Javascript
js querySelector和getElementById通过id获取元素的区别
Apr 20 Javascript
可在线编辑网页文字效果代码(单击)
Mar 02 Javascript
JS实现控制文本框的内容
Jul 10 Javascript
Angularjs中三种数据的绑定策略(“@”,“=”,“&”)
Dec 23 Javascript
详解jquery validate实现表单验证 (正则表达式)
Jan 18 Javascript
AngularJs实现聊天列表实时刷新功能
Jun 15 Javascript
原生JS实现ajax与ajax的跨域请求实例
Dec 01 Javascript
vue-cli3.0 脚手架搭建项目的过程详解
Oct 19 Javascript
在element-ui的el-tree组件中用render函数生成el-button的实例代码
Nov 05 Javascript
简单了解vue 插值表达式Mustache
Jul 22 Javascript
原生JavaScript实现购物车
Jan 10 Javascript
SwfUpload在IE10上不出现上传按钮的解决方法
Jun 25 #Javascript
Jquery选择子控件"大于号"和" "区别介绍及使用示例
Jun 25 #Javascript
Jquery动态改变图片IMG的src地址示例
Jun 25 #Javascript
js实现快速分享功能(你的文章分享工具)
Jun 25 #Javascript
用js实现table单元格高宽调整,兼容合并单元格(兼容IE6、7、8、FF)实例
Jun 25 #Javascript
javascript实现div的显示和隐藏的小例子
Jun 25 #Javascript
js中复制行和删除行的操作实例
Jun 25 #Javascript
You might like
解析:php调用MsSQL存储过程使用内置RETVAL获取过程中的return值
2013/07/03 PHP
php 注册时输入信息验证器的实现详解
2013/07/05 PHP
实例介绍PHP的Reflection反射机制
2014/08/05 PHP
php异步:在php中使用fsockopen curl实现类似异步处理的功能方法
2016/12/10 PHP
php 使用curl模拟ip和来源进行访问的实现方法
2017/05/02 PHP
PHP substr()函数参数解释及用法讲解
2017/11/23 PHP
使用onbeforeunload属性后的副作用
2007/03/08 Javascript
再谈javascript面向对象编程
2012/03/18 Javascript
Jquery的Tabs内容轮换效果实现代码,几行搞定
2014/02/12 Javascript
js判断登陆用户名及密码是否为空的简单实例
2016/05/16 Javascript
当jquery ajax遇上401请求的解决方法
2016/05/19 Javascript
javascript阻止事件冒泡和浏览器的默认行为
2017/01/21 Javascript
Vue学习笔记进阶篇之函数化组件解析
2017/07/21 Javascript
AjaxUpLoad.js实现文件上传功能
2018/03/02 Javascript
Layui给数据表格动态添加一行并跳转到添加行所在页的方法
2018/08/20 Javascript
jQuery实现动画、消失、显现、渐出、渐入效果示例
2018/09/06 jQuery
three.js搭建室内场景教程
2018/12/30 Javascript
Vue 3.x+axios跨域方案的踩坑指南
2019/07/04 Javascript
详解微信小程序自定义组件的实现及数据交互
2019/07/22 Javascript
使用Python3 编写简单信用卡管理程序
2016/12/21 Python
Python中装饰器学习总结
2018/02/10 Python
深入解析python中的实例方法、类方法和静态方法
2019/03/11 Python
用Python解数独的方法示例
2019/10/24 Python
python 实现二维字典的键值合并等函数
2019/12/06 Python
安装PyInstaller失败问题解决
2019/12/14 Python
Python实现图片识别加翻译功能
2019/12/26 Python
Python paramiko使用方法代码汇总
2020/11/20 Python
Hotels.com爱尔兰:全球酒店预订
2017/02/24 全球购物
新闻记者个人求职的自我评价
2013/11/28 职场文书
广告学专业自荐信范文
2014/02/24 职场文书
写字楼租赁意向书
2014/07/30 职场文书
幼儿园个人师德总结
2015/02/06 职场文书
大学生个人学年总结
2015/02/15 职场文书
超市收银员岗位职责
2015/04/07 职场文书
2015年感恩母亲节活动方案
2015/05/04 职场文书
无工作证明怎么写
2015/06/15 职场文书