
1、创建一个添加按钮,listeners事件中button的单击事件。
2、调用这个button按钮。
3、调整ext的grid表格中plugins属性的配置即可。
/**
* 自定义一个带编辑控制按钮的控件
*/
Ext.define('Ext.form.ControlEditField', {
extend : 'Ext.form.FieldContainer',
alias : 'widget.controleditfield',
groupFieldType : 'textfield',
groupFieldConfig : null,
layout : 'hbox',
width : 250,
initComponent : function() {
var me = this
me.items = []
me.width = me.width + 50
if (me.groupFieldConfig) {
me.groupFieldType = me.groupFieldConfig.xtype
|| me.groupFieldType
me.items = [me.groupFieldConfig, {
xtype : 'button',
text : me.groupFieldConfig.readOnly ? '当前关' : '当前开',
width : 50,
handler : function(btn) {
var form = btn.up()
var field = form.down(form.groupFieldType)
var readonly = field.readOnly
btn.setText(!readonly ? '当前关' : '当前开')
field.setReadOnly(!readonly)
}
}]
}
me.initLabelable()
me.initFieldAncestor()
me.callParent()
},
setValue : function(value) {
var me = this
var field = me.down(me.groupFieldType)
if (field) {
field.setValue(value)
}
},
getValue : function() {
var me = this
var field = me.down(me.groupFieldType)
if (field) {
return field.getValue()
}
}
})
Ext.create('Ext.form.Panel', {
title : 'FieldContainer Example',
width : 550,
bodyPadding : 10,
items : [{
xtype : 'controleditfield',
fieldLabel : 'Last Three Jobs',
labelWidth : 100,
width : 300,
groupFieldConfig : {
xtype : 'combo',
store : [['a', 'b'], ['c', 'd']]
}
}, {
xtype : 'controleditfield',
fieldLabel : 'Last Three Jobs',
labelWidth : 100,
width : 300,
id : 'test',
groupFieldConfig : {
xtype : 'textfield'
}
}, {
xtype : 'controleditfield',
fieldLabel : 'Last Three Jobs',
labelWidth : 100,
width : 300,
groupFieldConfig : {
xtype : 'datefield',
format : 'Y-m-d H:i:s'
}
}],
renderTo : Ext.getBody()
})
Ext.defer(function() {
Ext.getCmp('test').setValue("我我我我")
}, 5000)
控制函数自己写吧
假设你的grid和store都已经new好了,首先new一个Recordvar p = new Record({
workRecordId:'',
project_id:'',
taskStageId:'',
workRecordContent:'',
workRecordPlanhours:'',
workRecordRealhours:'',
workRecordProgress:'',
workRecordRemark:''
})
2.将grid停止可编辑状态
grid.stopEditing()
3.向这个grid的store插入数据
store.insert(store.getCount(), p)//我项目里插入到最后一行,所以store.getCount(),这个数字类型可以自己选择插入到任意行都好用的
4.将这个grid重新设定为可编辑状态
grid.startEditing(0, 0)
通过以上4个步骤,就可以完成添加了
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)