Ext.onReady(function() {
Ext.define('User', {
extend : 'Ext.data.Model',
fields : [{
name : 'userId',
type : 'int',
useNull : true//这样数字如果值为空则不会自动转成0,则提交时注意后台bean类中的属性int要用对象类型,否则解析出错
}, {
name : 'loginName',
type : 'string'
}, {
name : 'password',
type : 'string'
}, {
name : 'remark',
type : 'string'
}, {
name : 'roleId',
type : 'float',
useNull : true
}, {
name : 'rightId',
type : 'float',
useNull : true
}, {
name : 'platformNo',
type : 'string'
}, {
name : 'groupId',
type : 'float',
useNull : true
}, {
name : 'net',
type : 'string'
}, {
name : 'email',
type : 'string'
}, {
name : 'linkman',
type : 'string'
}, {
name : 'tel',
type : 'string'
}, {
name : 'fax',
type : 'string'
}, {
name : 'address',
type : 'string'
}],
idProperty : 'userId'// 极为重要的配置。关系到表格修改数据的获取
});
var store = new Ext.data.Store({
model : 'User',
pageSize : 3,
proxy : {
type : 'ajax',
url : 'baseUsers.action',
reader : {
type : 'json',
root : 'pageBean.list',
totalProperty : 'pageBean.total'
}
},
autoLoad : false
});
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit : 2
});
var grid = Ext.create('Ext.grid.Panel', {
tbar : [ {
xtype : 'button',
text : '新增',
handler : add
},{
xtype : 'button',
text : '提交修改',
handler : alter
}, {
xtype : 'button',
text : '删除',
handler : otherDelete
}],
title : 'All Products',
store : store,
columnLines : true,
selModel : Ext.create('Ext.selection.CheckboxModel'),
columns : [{
header : 'userId',
dataIndex : 'userId',
hidden:true
}, {
header : 'loginName',
dataIndex : 'loginName',
editor : {
allowBlank : false
}
}, {
header : 'password',
dataIndex : 'password',
editor : {
allowBlank : false
}
}, {
header : 'remark',
dataIndex : 'remark',
editor : {
allowBlank : false
}
}, {
header : 'roleId',
dataIndex : 'roleId',
editor : {
allowBlank : false
}
}, {
header : 'rightId',
dataIndex : 'rightId',
editor : {
allowBlank : false
}
}, {
header : 'platformNo',
dataIndex : 'platformNo',
editor : {
allowBlank : false
}
}, {
header : 'groupId',
dataIndex : 'groupId',
editor : {
allowBlank : false
}
}, {
header : 'net',
dataIndex : 'net',
editor : {
allowBlank : false
}
}, {
header : 'email',
dataIndex : 'email',
editor : {
allowBlank : false
}
}, {
header : 'linkman',
dataIndex : 'linkman',
editor : {
allowBlank : false
}
}, {
header : 'tel',
dataIndex : 'tel',
editor : {
allowBlank : false
}
}, {
header : 'fax',
dataIndex : 'fax',
editor : {
allowBlank : false
}
}, {
header : 'address',
dataIndex : 'address',
editor : {
allowBlank : false
}
}],
forceFit : true,
dockedItems : [{
xtype : 'pagingtoolbar',
store : store, // same store GridPanel is
// using
dock : 'bottom',
displayInfo : true
}],
renderTo : 'userMngDiv',
plugins : [cellEditing]
// autoRender:true
});
store.loadPage(1);
var p = parent.Ext.getCmp('contentTabs');
// alert(p);
function alter() {
var records = store.getUpdatedRecords();// 获取修改的行的数据,无法获取幻影数据
var phantoms=store.getNewRecords( ) ;//获得幻影行
records=records.concat(phantoms);//将幻影数据与真实数据合并
if (records.length == 0) {
Ext.MessageBox.show({
title : "提示",
msg : "没有任何数据被修改过!"
// icon: Ext.MessageBox.INFO
});
return;
} else {
Ext.Msg.confirm("请确认", "是否真的要修改数据?", function(button, text) {
if (button == "yes") {
var data = [];
// alert(records);
Ext.Array.each(records, function(record) {
data.push(record.data);
// record.commit();// 向store提交修改数据,页面效果
});
Ext.Ajax.request({
url : 'alterUsers.action',
params : {
alterUsers : Ext.encode(data)
},
method : 'POST',
timeout : 2000,
success : function(response, opts) {
var success = Ext.decode(response.responseText).success;
// 当后台数据同步成功时
if (success) {
Ext.Array.each(records, function(record) {
// data.push(record.data);
record.commit();// 向store提交修改数据,页面效果
});
} else {
Ext.MessageBox.show({
title : "提示",
msg : "数据修改失败!"
// icon: Ext.MessageBox.INFO
});
}
}
});
}
});
}
}
// 传递对象删除
// function deleteUsers() {
// var data = grid.getSelectionModel().getSelection();
// // alert(data);
// if (data.length == 0) {
// Ext.MessageBox.show({
// title : "提示",
// msg : "请先选择您要操作的行!"
// // icon: Ext.MessageBox.INFO
// });
// return;
// } else {
// Ext.Msg.confirm("请确认", "是否真的要删除数据?", function(button, text) {
// if (button == "yes") {
// var ids = [];
// Ext.Array.each(data, function(record) {
// ids.push(record.data);
// });
// Ext.Ajax.request({
// url : 'deleteUsers.action',
// params : {
// deleteUsers : Ext.encode(ids)
// },
// method : 'POST',
// // timeout : 2000,//默认30秒
// success : function(response, opts) {
// var success = Ext.decode(response.responseText).success;
// // 当后台数据同步成功时
// if (success) {
// Ext.Array.each(data, function(record) {
// store.remove(record);// 页面效果
// });
// } else {
// Ext.MessageBox.show({
// title : "提示",
// msg : "数据删除失败!"
// // icon: Ext.MessageBox.INFO
// });
// }
//
// }
// });
// }
// });
//
// }
// }
// 编码ID删除
function otherDelete() {
var data = grid.getSelectionModel().getSelection();
// alert(data);
if (data.length == 0) {
Ext.MessageBox.show({
title : "提示",
msg : "请先选择您要操作的行!"
// icon: Ext.MessageBox.INFO
});
return;
} else {
Ext.Msg.confirm("请确认", "是否真的要删除数据?", function(button, text) {
if (button == "yes") {
var ids = [];
Ext.Array.each(data, function(record) {
var userId=record.get('userId');
//如果删除的是幻影数据,则id就不传递到后台了,直接在前台删除即可
if(userId){
ids.push(userId);
}
});
Ext.Ajax.request({
url : 'deleteUsers.action',
params : {
deleteIds : ids.join(',')
},
method : 'POST',
// timeout : 2000,//默认30秒
success : function(response, opts) {
// store.loadPage(1);
var success = Ext.decode(response.responseText).success;
// 当后台数据同步成功时
if (success) {
Ext.Array.each(data, function(record) {
store.remove(record);// 页面效果
});
} else {
Ext.MessageBox.show({
title : "提示",
msg : "数据删除失败!"
// icon: Ext.MessageBox.INFO
});
}
}
});
}
});
}
}
function add(){
store.insert(0,new User());
}
});
Ext.onReady(function() {
Ext.define('User', {
extend : 'Ext.data.Model',
fields : [{
name : 'userId',
type : 'int',
useNull : true//这样数字如果值为空则不会自动转成0,则提交时注意后台bean类中的属性int要用对象类型,否则解析出错
}, {
name : 'loginName',
type : 'string'
}, {
name : 'password',
type : 'string'
}, {
name : 'remark',
type : 'string'
}, {
name : 'roleId',
type : 'float',
useNull : true
}, {
name : 'rightId',
type : 'float',
useNull : true
}, {
name : 'platformNo',
type : 'string'
}, {
name : 'groupId',
type : 'float',
useNull : true
}, {
name : 'net',
type : 'string'
}, {
name : 'email',
type : 'string'
}, {
name : 'linkman',
type : 'string'
}, {
name : 'tel',
type : 'string'
}, {
name : 'fax',
type : 'string'
}, {
name : 'address',
type : 'string'
}],
idProperty : 'userId'// 极为重要的配置。关系到表格修改数据的获取
});
var store = new Ext.data.Store({
model : 'User',
pageSize : 3,
proxy : {
type : 'ajax',
url : 'baseUsers.action',
reader : {
type : 'json',
root : 'pageBean.list',
totalProperty : 'pageBean.total'
}
},
autoLoad : false
});
var cellEditing = Ext.create('Ext.grid.plugin.CellEditing', {
clicksToEdit : 2
});
var grid = Ext.create('Ext.grid.Panel', {
tbar : [ {
xtype : 'button',
text : '新增',
handler : add
},{
xtype : 'button',
text : '提交修改',
handler : alter
}, {
xtype : 'button',
text : '删除',
handler : otherDelete
}],
title : 'All Products',
store : store,
columnLines : true,
selModel : Ext.create('Ext.selection.CheckboxModel'),
columns : [{
header : 'userId',
dataIndex : 'userId',
hidden:true
}, {
header : 'loginName',
dataIndex : 'loginName',
editor : {
allowBlank : false
}
}, {
header : 'password',
dataIndex : 'password',
editor : {
allowBlank : false
}
}, {
header : 'remark',
dataIndex : 'remark',
editor : {
allowBlank : false
}
}, {
header : 'roleId',
dataIndex : 'roleId',
editor : {
allowBlank : false
}
}, {
header : 'rightId',
dataIndex : 'rightId',
editor : {
allowBlank : false
}
}, {
header : 'platformNo',
dataIndex : 'platformNo',
editor : {
allowBlank : false
}
}, {
header : 'groupId',
dataIndex : 'groupId',
editor : {
allowBlank : false
}
}, {
header : 'net',
dataIndex : 'net',
editor : {
allowBlank : false
}
}, {
header : 'email',
dataIndex : 'email',
editor : {
allowBlank : false
}
}, {
header : 'linkman',
dataIndex : 'linkman',
editor : {
allowBlank : false
}
}, {
header : 'tel',
dataIndex : 'tel',
editor : {
allowBlank : false
}
}, {
header : 'fax',
dataIndex : 'fax',
editor : {
allowBlank : false
}
}, {
header : 'address',
dataIndex : 'address',
editor : {
allowBlank : false
}
}],
forceFit : true,
dockedItems : [{
xtype : 'pagingtoolbar',
store : store, // same store GridPanel is
// using
dock : 'bottom',
displayInfo : true
}],
renderTo : 'userMngDiv',
plugins : [cellEditing]
// autoRender:true
});
store.loadPage(1);
var p = parent.Ext.getCmp('contentTabs');
// alert(p);
function alter() {
var records = store.getUpdatedRecords();// 获取修改的行的数据,无法获取幻影数据
var phantoms=store.getNewRecords( ) ;//获得幻影行
records=records.concat(phantoms);//将幻影数据与真实数据合并
if (records.length == 0) {
Ext.MessageBox.show({
title : "提示",
msg : "没有任何数据被修改过!"
// icon: Ext.MessageBox.INFO
});
return;
} else {
Ext.Msg.confirm("请确认", "是否真的要修改数据?", function(button, text) {
if (button == "yes") {
var data = [];
// alert(records);
Ext.Array.each(records, function(record) {
data.push(record.data);
// record.commit();// 向store提交修改数据,页面效果
});
Ext.Ajax.request({
url : 'alterUsers.action',
params : {
alterUsers : Ext.encode(data)
},
method : 'POST',
timeout : 2000,
success : function(response, opts) {
var success = Ext.decode(response.responseText).success;
// 当后台数据同步成功时
if (success) {
Ext.Array.each(records, function(record) {
// data.push(record.data);
record.commit();// 向store提交修改数据,页面效果
});
} else {
Ext.MessageBox.show({
title : "提示",
msg : "数据修改失败!"
// icon: Ext.MessageBox.INFO
});
}
}
});
}
});
}
}
// 传递对象删除
// function deleteUsers() {
// var data = grid.getSelectionModel().getSelection();
// // alert(data);
// if (data.length == 0) {
// Ext.MessageBox.show({
// title : "提示",
// msg : "请先选择您要操作的行!"
// // icon: Ext.MessageBox.INFO
// });
// return;
// } else {
// Ext.Msg.confirm("请确认", "是否真的要删除数据?", function(button, text) {
// if (button == "yes") {
// var ids = [];
// Ext.Array.each(data, function(record) {
// ids.push(record.data);
// });
// Ext.Ajax.request({
// url : 'deleteUsers.action',
// params : {
// deleteUsers : Ext.encode(ids)
// },
// method : 'POST',
// // timeout : 2000,//默认30秒
// success : function(response, opts) {
// var success = Ext.decode(response.responseText).success;
// // 当后台数据同步成功时
// if (success) {
// Ext.Array.each(data, function(record) {
// store.remove(record);// 页面效果
// });
// } else {
// Ext.MessageBox.show({
// title : "提示",
// msg : "数据删除失败!"
// // icon: Ext.MessageBox.INFO
// });
// }
//
// }
// });
// }
// });
//
// }
// }
// 编码ID删除
function otherDelete() {
var data = grid.getSelectionModel().getSelection();
// alert(data);
if (data.length == 0) {
Ext.MessageBox.show({
title : "提示",
msg : "请先选择您要操作的行!"
// icon: Ext.MessageBox.INFO
});
return;
} else {
Ext.Msg.confirm("请确认", "是否真的要删除数据?", function(button, text) {
if (button == "yes") {
var ids = [];
Ext.Array.each(data, function(record) {
var userId=record.get('userId');
//如果删除的是幻影数据,则id就不传递到后台了,直接在前台删除即可
if(userId){
ids.push(userId);
}
});
Ext.Ajax.request({
url : 'deleteUsers.action',
params : {
deleteIds : ids.join(',')
},
method : 'POST',
// timeout : 2000,//默认30秒
success : function(response, opts) {
// store.loadPage(1);
var success = Ext.decode(response.responseText).success;
// 当后台数据同步成功时
if (success) {
Ext.Array.each(data, function(record) {
store.remove(record);// 页面效果
});
} else {
Ext.MessageBox.show({
title : "提示",
msg : "数据删除失败!"
// icon: Ext.MessageBox.INFO
});
}
}
});
}
});
}
}
function add(){
store.insert(0,new User());
}
});