编辑的时候。添加一行
function add(){
alert('add');
//定义一个新的row
var row = new Ext.data.Record({
function_id:'', //这里是和ColumnModel里面的dataIndex相互对应的
function_name:'',
function_url:'http://',
function_alias:'',
modify_user:'',
is_default:''
});
grid.stopEditing();
gridstore.insert(0,row); //在第一行插入这一行 这个的调用对象是store
grid.startEditing(0,1); //在哪一行开始编辑
}
Editor和EditorGridPanel的配置
//editor的配置
var editorname = new Ext.form.TextField({
allowBlank : false,
maxLength : 120
});
var editorage = new Ext.form.TextField({
allowBlank : false,
maxLength : 120
});
var editorhobby = new Ext.form.TextField({
allowBlank : false,
maxLength : 120
});
var editorsport = new Ext.form.TextField({
allowBlank : false,
maxLength : 120
});
//表格用到的数据存储器
var gridstore = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url:''
}),
reader:new Ext.data.JsonReader({
totalProperty:'totalProperty',
root:'root'
},[
{name:'name'},
{name:'age'},
{name:'hobby'},
{name:'sport'}
])
});
//配置表格的批量选择
var sm = new Ext.grid.CheckboxSelectionModel();
//表格的cm属性.这里将sm设置在里头
var cm=new Ext.grid.ColumnModel([sm,
{header:'姓名',dataIndex:'name',editor:editorname},
{header:'年龄',dataIndex:'age',editor:editorage},
{header:'爱好',dataIndex:'hobby',editor:editorhobby},
{header:'运动',dataIndex:'sport',editor:editorsport}
]);
//可编辑的表格
var grid = new Ext.grid.EditorGridPanel({
width:650,
height:290,
sm:sm,
cm:cm,
store:gridstore
});
效果截图: