extjs重新激活grid_extjs4 grid 新增、删除、修改

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'// 极为重要的配置。关系到表格修改数据的获取

});

varstore =newExt.data.Store({

model : 'User',

pageSize : 3,

proxy : {

type : 'ajax',

url : 'baseUsers.action',

reader : {

type : 'json',

root : 'pageBean.list',

totalProperty : 'pageBean.total'

}

},

autoLoad : false

});

varcellEditing = Ext.create('Ext.grid.plugin.CellEditing', {

clicksToEdit : 2

});

vargrid = 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);

varp = parent.Ext.getCmp('contentTabs');

// alert(p);

functionalter() {

varrecords = store.getUpdatedRecords();// 获取修改的行的数据,无法获取幻影数据

varphantoms=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") {

vardata = [];

// 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) {

varsuccess = 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删除

functionotherDelete() {

vardata = 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") {

varids = [];

Ext.Array.each(data, function(record) {

varuserId=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);

varsuccess = 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

});

}

}

});

}

});

}

}

functionadd(){

store.insert(0,newUser());

}

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值