复制代码 代码如下:
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 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
});
}
});
}
}]
});
}