日期:2014-05-16  浏览次数:20737 次

搞不明白的 Extjs 可编辑表格 保存问题 !!! 希望大家帮帮忙,谢谢!!!
我想对表格进行编辑,用以下代码实现了可以编辑整行的效果,而且还带有保存和取消按钮的那种,如下图所以:

代码:
定义可编辑字段
var frozenStateVal =  new Ext.form.ComboBox({  
id:'frozenStateVal',
        editable: false,  
        displayField: "froSta",  
        mode: "local",  
        triggerAction: "all", 
        store: [['0','未冻结'],['1', '冻结']]
});

var cm = new Ext.grid.ColumnModel({
defaults: {align: 'center'},
columns:[
new Ext.grid.RowNumberer(),
{header:'帐户名',dataIndex:'loginName',width:150},
{header:'用户ID',dataIndex:'id'},          
{header:'账户余额',dataIndex:'tradeCode',align:'right'},
{header:'冻结金额',dataIndex:'province',align:'right'},
{header:'<span>账户状态</span>',dataIndex:'frozenState',renderer:frozenStatefun,editor: frozenStateVal},
{header:'用户级别',dataIndex:'roleType',renderer:typefun},
{header:'注册日期',dataIndex:'regDate',width: 120},
{header:'激活日期',dataIndex:'actDate',width: 120}         
   ]
});

封装了一个使用extjs表格的通用方法,里面定义了一些的配置,在使用grid时直接继承这个就行,可以跳过斜体字代码
ContentGrid = function(config) {
config = config || {};
Ext.applyIf(config, {
stripeRows: true, 
columnLines: true,
loadMask: true, 
viewConfig: {forceFit: true},
autoScroll: true,
clicksToEdit: 2,  
sm: new Ext.grid.RowSelectionModel({singleSelect: true})
});
ContentGrid.superclass.constructor.call(this, config);
this.initAction();
};
Ext.extend(ContentGrid, Ext.grid.EditorGridPanel, {
initAction: function() {
}
});

下面是对编辑表格的保存操作代码
var editor = new Ext.ux.grid.RowEditor({ });
contentGrid = new ContentGrid({
region: 'center',
title: '账户信息管理',
store: store,
cm: cm,
tbar: ['-','注册开始时间:',beginDate2,'-',queryBtn,'','-'],
bbar: pageBbar(store),
viewConfig: {   },
           plugins: [editor]
});
editor.on({ 
//  scope: editor.saveText,
 afteredit: function(roweditor,changes,record, rowIndex){
 Ext.Ajax.request({ 
     url   : Constant.ROOT_PATH + '/orderquery/backFrozenUser.do',
     method: 'POST',
     params: {userId:record.get('id'),orderState:Ext.getCmp("frozenStateVal").getValue()},
     success: function() { 
store.reload();
     },failure: function() { 
showErr(Constant.MSG_ERR); 
store.reload();
 } 
 });
 }
});

后台已经能够获得要修改的参数,但是问题是:
1. 怎么在点击取消按扭时同步刷新页面,那个保存和取消按扭的方法写在了哪里,找不到。
2. 有时候点击保存按钮不会到后台去执行相应的方法,也就是没有保存更新的数据,为什么?
   有时候需要在进行一次更新保存才可以,不知道为什么?总