在EditorGridPanel中插入一行(經常在增加的時候用到)
阿新 • • 發佈:2019-02-07
編輯的時候。新增一行
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
});
效果截圖: