ext 代码生成器


Posted in Javascript onAugust 07, 2009

本文件为:ext_editgrid_products.js,用来显示,编辑,删除products表的数据。

var productsgrid; 
var productsstore; 
var productslimit = 25; //每页显示条数 
var productsListPostUrl = "/management/procrequest/Proc_products.ashx?action=getlist"; 
var productsModifyPostUrl = "/management/procrequest/Proc_products.ashx?action=modify"; 
var productsDeletePostUrl = "/management/procrequest/Proc_products.ashx?action=del"; 
function initproductsGrid(containerid) { 
Ext.menu.RangeMenu.prototype.icons = { 
gt: 'images/greater_then.png', 
lt: 'images/less_then.png', 
eq: 'images/equals.png' 
}; 
Ext.grid.filter.StringFilter.prototype.icon = 'images/find.png'; 
Ext.QuickTips.init(); 
function formatDate(value) { 
return value ? value.dateFormat('M d, Y') : ''; 
}; 
var fm = Ext.form; 
var sm = new Ext.grid.CheckboxSelectionModel(); 
var cm = new Ext.grid.ColumnModel([ 
sm, 
{ 
id:'productId', 
header: '产品编号', 
dataIndex: 'productId', 
sortable: true, 
width:70, 
editor: new fm.NumberField({ 
allowBlank: false, 
allowNegative: false 
}) 
}, 
{ 
header: '产品名称', 
dataIndex: 'productName', 
sortable: true, 
width:120, 
editor: new fm.TextField({ 
allowBlank: false, 
allowNegative: false 
}) 
}, 
{ 
header: '金额', 
dataIndex: 'money', 
sortable: true, 
width:120, 
editor: new fm.NumberField({ 
allowBlank: false, 
allowNegative: false 
}) 
}, 
{ 
header: '地址', 
dataIndex: 'address', 
sortable: true, 
width:120, 
editor: new fm.TextField({ 
allowBlank: false, 
allowNegative: false 
}) 
}, 
{ 
header: '电话', 
dataIndex: 'tel', 
sortable: true, 
width:120, 
editor: new fm.TextField({ 
allowBlank: false, 
allowNegative: false 
}) 
}, 
{ 
header: '备注', 
dataIndex: 'remark', 
sortable: false, 
width:550, 
editor: new fm.myHtmlEditor({ 
allowBlank: false, 
allowNegative: false 
}) 
}, 
{ 
header: '端口', 
dataIndex: 'port', 
sortable: true, 
width:70, 
editor: new fm.NumberField({ 
allowBlank: false, 
allowNegative: false 
}) 
} 
]); 
cm.defaultSortable = true; 
/* 
var Plant = Ext.data.Record.create([ 
]); 
*/ 
productsstore = new Ext.data.JsonStore({ 
root: 'list', 
totalProperty: 'totalCount', 
idProperty: 'productId', 
remoteSort: true, 
fields: [ 
{name: 'productId' },{name: 'productName' },{name: 'money' },{name: 'address' },{name: 'tel' },{name: 'remark' },{name: 'port' } 
], 
proxy: new Ext.data.ScriptTagProxy({ 
url: productsListPostUrl 
}) 
}); 
productsstore.setDefaultSort('productId', 'desc'); 
var filters = new Ext.grid.GridFilters({ 
filters: [ 
{ type: 'string', dataIndex: 'productId' }, { type: 'string', dataIndex: 'productName' }, { type: 'string', dataIndex: 'money' }, { type: 'string', dataIndex: 'address' }, { type: 'string', dataIndex: 'tel' }, { type: 'string', dataIndex: 'remark' }, { type: 'string', dataIndex: 'port' } 
    ] 
}); 
var pagingBar = new Ext.PagingToolbar({ 
pageSize: productslimit, 
store: productsstore, 
displayInfo: true, 
displayMsg: '第 {0} - {1} 条记录,总共 {2} 条记录', 
emptyMsg: "没有记录" 
}); 
productsgrid = new Ext.grid.EditorGridPanel({ 
store: productsstore, 
cm: cm, 
sm: sm, 
bodyStyle: 'width:100%', 
autoWidth: true, 
height: 620, 
renderTo: containerid, 
autoExpandColumn: 'productId', 
frame: true, 
clicksToEdit: 2, 
plugins: [filters], 
loadMask: true, 
enableTabScroll: true, 
tbar: [{ 
text: '添加', 
tooltip: '添加新记录', 
iconCls: 'add', 
handler:function(){ 
openTab("addproducts", "添加products", null, initAddproductsForm); 
} 
}, 
'-', { 
text: '编辑', 
tooltip: '编辑选中记录', 
iconCls: 'option', 
handler: function() { 
var selectedRow = productsgrid.getSelectionModel().getSelections(); 
if (selectedRow) { 
var obj = selectedRow[0]; 
if (!obj) 
return; 
var id = obj.get("productId"); 
openTab("editproducts", "编辑products", null, initAddproductsForm, id, obj); 
} 
} 
}, 
'-', { 
text: '删除', 
tooltip: '删除选中记录', 
iconCls: 'remove', 
handler: function() { 
var selectedRow = productsgrid.getSelectionModel().getSelections(); 
Ext.MessageBox.confirm('Confirm', '你确定要删除你所选定的' + selectedRow.length + "项吗?", function(btn) { 
if (btn == 'yes') { 
if (selectedRow) { 
for (var i = 0; i < selectedRow.length; i++) { 
var obj = selectedRow[i]; 
var id = obj.get("productId"); 
productsstore.remove(obj); 
$.ajax({ 
type: "POST", 
url: productsDeletePostUrl, 
dataType: "json", 
data: "recordid=" + id, 
success: function(msg) { 
if (msg[0] && msg[0].string != "success") 
productsstore.reload(); 
} 
}); 
} 
} 
} 
}); 
} 
}], 
bbar: pagingBar 
}); 
productsstore.load({ params: { start: 0, limit: productslimit} }); 
productsgrid.on("afteredit", afterEdit, productsgrid); 
function afterEdit(obj) { 
var r = obj.record; //获取被修改的行 
var fildname = obj.field; //获取被修改的列 
var id = r.get("productId"); 
var fildval = obj.value; 
$.ajax({ 
type: "POST", 
url: productsModifyPostUrl, 
dataType: "json", 
data: { action: 'modify', fildname: fildname, id: id, fildval: fildval }, 
complete: function() { 
}, 
success: function(msg) { 
} 
}); 
} 
}

本文件为ext_add_products.js,用来添加或者编辑products表。
var productsAddPostUrl = "/management/procrequest/Proc_products.ashx?action=add"; 
var productsUpdatePostUrl = "/management/procrequest/Proc_products.ashx?action=update"; 
function initAddproductsForm(containerid, idstr, rowObj) { 
if (!idstr) 
idstr = containerid; 
var productsForm = new Ext.FormPanel({ 
labelWidth: 100, // label settings here cascade unless overridden 
url: productsAddPostUrl, 
frame: true, 
bodyStyle: 'padding:5px 5px 0', 
autoWidth: true, 
defaults: { width: '350' }, 
defaultType: 'textfield', 
renderTo: containerid, 
items: [ 
{ 
xtype: 'hidden', 
name: 'productId', 
id: 'productId' + idstr, 
value: null == rowObj ? null : rowObj.get("productId"), 
readOnly: true 
} , { 
xtype: 'textfield', 
fieldLabel: '商品名称', 
height: 20, 
name: 'productName', 
allowBlank: false, 
value: null == rowObj ? null : rowObj.get("productName"), 
id: 'productName' + idstr 
} 
, { 
xtype: 'numberfield', 
fieldLabel: '价格', 
height: 20, 
name: 'money', 
allowBlank: false, 
value: null == rowObj ? null : rowObj.get("money"), 
id: 'money' + idstr 
} 
, { 
xtype: 'textfield', 
fieldLabel: '地址', 
height: 20, 
name: 'address', 
value: null == rowObj ? null : rowObj.get("address"), 
id: 'address' + idstr 
} 
, { 
xtype: 'textfield', 
fieldLabel: '电话', 
height: 20, 
name: 'tel', 
value: null == rowObj ? null : rowObj.get("tel"), 
id: 'tel' + idstr 
} 
, { 
xtype: 'myhtmleditor', 
fieldLabel: '备注', 
height: 400, width: 600, 
name: 'remark', 
value: null == rowObj ? null : rowObj.get("remark"), 
id: 'remark' + idstr 
} 
, { 
xtype: 'numberfield', 
fieldLabel: '端口', 
height: 20, 
name: 'port', 
value: null == rowObj ? null : rowObj.get("port"), 
id: 'port' + idstr 
} 
], 
buttons: [{ 
text: '保存', 
handler: function() { 
if (!productsForm.form.isValid()) 
return; 
productsForm.form.submit({ 
meghod: 'post', 
url: !isNaN(idstr) && parseInt(idstr) > 0 ? productsUpdatePostUrl : productsAddPostUrl, 
waitMsg: '正在保存,请稍候...', 
success: function() { 
Ext.MessageBox.show({ 
title: '保存结果', 
msg: '保存成功', 
buttons: Ext.MessageBox.OK, 
icon: Ext.MessageBox.INFO 
}); 
}, 
failure: function() { 
Ext.MessageBox.show({ 
title: '保存结果', 
msg: '保存失败', 
buttons: Ext.MessageBox.OK, 
icon: Ext.MessageBox.ERROR 
}); 
} 
}); 
} 
}] 
}); 
}
Javascript 相关文章推荐
ext checkboxgroup 回填数据解决
Aug 21 Javascript
JS 有名函数表达式全面解析
Mar 19 Javascript
基于jQuery UI CSS Framework开发Widget的经验
Aug 21 Javascript
从阶乘函数对比Javascript和C#的异同
May 31 Javascript
使用jQuery中的when实现多个AJAX请求对应单个回调的例子分享
Apr 23 Javascript
jquery自定义表单验证插件
Oct 12 Javascript
Bootstrap栅格系统的使用和理解2
Dec 14 Javascript
Angularjs 实现动态添加控件功能
May 25 Javascript
vue  自定义组件实现通讯录功能
Sep 30 Javascript
vue中的适配px2rem示例代码
Nov 19 Javascript
解决vue的过渡动画无法正常实现问题
Oct 31 Javascript
JS实现公告上线滚动效果
Jan 10 Javascript
JavaScript 的方法重载效果
Aug 07 #Javascript
JQuery 小练习(实例代码)
Aug 07 #Javascript
js正确获取元素样式详解
Aug 07 #Javascript
JavaScript 乱码问题
Aug 06 #Javascript
jquery ui dialog里调用datepicker的问题
Aug 06 #Javascript
jquery select(列表)的操作(取值/赋值)
Aug 06 #Javascript
asp(javascript)全角半角转换代码 dbc2sbc
Aug 06 #Javascript
You might like
用session做客户验证时的注意事项
2006/10/09 PHP
Notice: Undefined index: page in E:\PHP\test.php on line 14
2010/11/02 PHP
php获取远程文件的内容和大小
2015/11/03 PHP
PHP数字前补0的自带函数sprintf 和number_format的用法(详解)
2017/02/06 PHP
PHP解决中文乱码
2017/04/28 PHP
js tab 选项卡
2009/04/26 Javascript
js获取本机的外网/广域网ip地址完整源码
2013/08/12 Javascript
jQuery中on()方法用法实例详解
2015/02/06 Javascript
jQuery链式操作实例分析
2015/11/16 Javascript
基于HTML+CSS,jQuery编写的简易计算器后续(添加了键盘监听)
2016/01/05 Javascript
在AngularJS框架中处理数据建模的方式解析
2016/03/05 Javascript
微信小程序学习之数据处理详解
2017/07/05 Javascript
JS运动改变单物体透明度的方法分析
2018/01/23 Javascript
浅析vue深复制
2018/01/29 Javascript
vue项目tween方法实现返回顶部的示例代码
2018/03/02 Javascript
angular4 共享服务在多个组件中数据通信的示例
2018/03/30 Javascript
微信小程序的tab选项卡的实现效果
2019/05/15 Javascript
VSCode 添加自定义注释的方法(附带红色警戒经典注释风格)
2020/08/27 Javascript
原生JS实现音乐播放器的示例代码
2021/02/25 Javascript
使用python的chardet库获得文件编码并修改编码
2014/01/22 Python
Python数据类型详解(三)元祖:tuple
2016/05/08 Python
python3.5仿微软计算器程序
2020/03/30 Python
Python异常对代码运行性能的影响实例解析
2018/02/08 Python
Python 基于FIR实现Hilbert滤波器求信号包络详解
2020/02/26 Python
HTML5之WebGL 3D概述(下)—借助类库开发及框架介绍
2013/01/31 HTML / CSS
基于HTML5的齿轮动画特效
2016/02/29 HTML / CSS
详解html5 shiv.js和respond.min.js
2018/01/24 HTML / CSS
Java基础知识面试题
2014/03/25 面试题
opencv实现图像平移效果
2021/03/24 Python
数学专业毕业生自荐信
2013/11/10 职场文书
个人四风问题原因分析及整改措施
2014/09/28 职场文书
幼儿园教师自荐书
2015/03/06 职场文书
毕业实习单位意见
2015/06/04 职场文书
谢师宴家长致辞
2015/07/27 职场文书
2016年大学迎新晚会工作总结
2015/10/15 职场文书
简单聊一聊SQL注入及防止SQL注入
2022/03/23 MySQL