需求:在grid中显示的数据是否可以编辑,有如下规则:现在有两列,一个是 itemtype,另一列是第一列code。itemtype有两个值(可用:1,删除:0 ),如果itemtype=‘可用’或'1'则code是不可以编辑的;如果itemtype=‘删除’或'0',则code是可以编辑的。其他列都是可以编辑的,不受任何影响。
这里我们用到beforeedit事件,对象是一个单元格,也就是:单元格编辑前发生的事件,此单元格是否可以编辑。具体内容如下:
-------------------------------------------------------------------------------------------------
var mainGrid = new Ext.grid.EditorGridPanel({
title : "出入金类型设置",
id : this.genId("main"),
//plugins: [editor],
loadMask : true,
autoScorll : true,
closable : true,
layout : 'fit',
collapsed : false,
autoHeight : false,
autoWidth : false,
store : _this.moneyStore,
cm : _this.moneycm,
//sm : _this.moneyCheckbox,
//frame : true,
clicksToEdit : 1,
listeners : {
"beforedestroy" : function(obj) {
obj.getStore().removeAll();
obj = null;
},
//这个方法对于实现需求很重要
"beforeedit" : function(iEventobj){//参数iEventobj是单元格
var col = iEventobj.column;//获取单元格的列
var row = iEventobj.row;//获取单元格的行
var _record = iEventobj.record;//获取当前选中的这个单元格所在的一整行数据
var itemtype = _record.get("itemtype");//获取这行数据中itemtype对应的值
if (0 == col && '1' == itemtype){//如果itemtype=1,为可用状态,则返回false,返回false就是不可编辑
return false;
}
if (0 == col && null == itemtype){//如果itemtype=null,也为不可编辑
return false;
}
/* if (0 == col && "入金" == itemtype){//如果itemtype为汉字'可用',也不可编辑
return false;
}
//以上这些都仅限于第一列,所以都有判断col是否为0
return true;
}
},
tbar:[{
xtype : 'buttongroup',
defaults : {
scale : 'small'
},
layoutConfig : {
columns : 3
},
items : [{
xtype : "button",
text : "查询",
icon : "image
axun.png",
handler : this.fn_query
}, {
xtype : "button",
text : "新增",
icon : "image/add.png",
handler:this.fn_add
}, {
xtype : "button",
text : "保存",
icon : "image
ve.png",
handler:this.fn_save
}]
}],
bbar : [{
xtype : "paging",
pageSize : gLimit,
store : this.limitStore,
displayInfo : true,
displayMsg : '数据第 {0}条 - 第{1}条,共 {2}条',
emptyMsg : "没有数据 "
}]
});
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。