PDA

View Full Version : the insert of grid not work



superbinary
14 Jul 2010, 7:02 PM
the insert not works. and i really can't figure out what's wrong:(... thanks very much.

Ext.onReady(
function()
{
IniTargetGrid();

});

function IniTargetGrid()
{
var targetRecord = Ext.data.Record.create([
{name:'col_id',type:'string'},
{name:'col_book',type:'string'},
{name:'col_chapter',type:'string'},
{name:'col_target',type:'string'}
]);

var targetData=[['id0','book0','chapter0','target0']];

var targetStore = new Ext.data.Store({
proxy:new Ext.data.MemoryProxy(targetData),
reader:new Ext.data.ArrayReader({},targetRecord)
});

targetStore.load();


var targetCm = new Ext.grid.ColumnModel([
new Ext.grid.RowNumberer(),
{header:'book',dataIndex:'col_book'},
{header:'chapter',dataIndex:'col_chapter'},
{header:'target',dataIndex:'col_target'}
]);

var targetGrid = new Ext.grid.EditorGridPanel({
renderTo:'target_grid',
cm:targetCm,
store:targetStore,
tbar: [{
text: 'add',
handler: function(){
var e = new targetRecord({
col_id:3,
col_book: 'a',
col_chapter: 'a',
col_target: 'a'
});
targetGrid.stopEditing();
targetStore.insert(0,e);
targetGrid.startEditing(0,0);
}
}]
});

}

superbinary
14 Jul 2010, 9:16 PM
i've put it right.. http://www.sencha.com/forum/showthread.php?93639-One-row-from-JSON-store-displays-in-Grid
it really tortured me all the day...

the answer is. height.

fay
15 Jul 2010, 12:09 AM
It is actually inserting the record, it's just that you've not specified a height for the EditorGridPanel. For the purposes of your example, just add autoHeight: true to the grid's config:



// ...
renderTo:'target_grid',
autoHeight: true,
// ...


Please read the docs (http://www.sencha.com/deploy/dev/docs/?class=Ext.grid.EditorGridPanel) about renderTo and autoHeight when you come to expand your example to use within layouts/containers/etc.