2010-03-08 48 views
0

我有TabPanel,其中包含连接到Store的Grid。ExtJS:当其底层存储为空时,从Tabpanel中删除网格

几个事件可能会从商店中删除元素。

我希望当商店是空的,并且可能在我的代码中有一个位置检查此事件时,将从TabPanel中移除网格。

我曾考虑过使用商店监听器,但不幸的是这会导致Ext代码出现异常。 我的假设是发生这种情况是因为渲染是在网格从tabpanel移除之后执行的。

任何想法如何完成这样的任务,而不会搞砸分机非常感谢。 谢谢:)

顺便说一句,这是一个代码摘录:

var myStore = new Ext.data.Store({ 
reader: new Ext.data.JsonReader({fields: MyRecord}), 
listeners:{ 
    'clear': function(store, recs) { 
    myTabPanel.remove(myGrid); 
    }, 
    'remove': function(store, rec, idx) { 
    if (store.getCount() == 0) { 
    myTabPanel.remove(myGrid); 
    } 
    } 
} 
}); 

var myGrid = new Ext.grid.GridPanel({ 
id: "myGrid", 
title: "A Grid", 
store: myStore, 
frame:false, 
border:false, 
columns: [ 
{ 
    header: 'Remove', 
    align:'center', 
    width: 45, 
    sortable: false, 
    renderer: function(value, metaData, record, rowIndex, colIndex, store) { 
    return '<img src="images/remove.png" width="34" height="18"/>'; 
    } 
},{ 
    header: 'Some Data', 
    dataIndex: 'data', 
    sortable: true 
} 
], 
listeners:{ 
    'cellclick':function(grid, rowIndex, colIndex, e){ 
    var rec = myStore.getAt(rowIndex); 
    if(colIndex == 0){ 
    myStore.remove(rec); 
    } 
    } 
} 
}); 

var myTabPanel= new Ext.TabPanel({ 
activeTab: 0, 
items: [ fooPanel, barPanel, myGrid] 
}); 

回答

0

问题解决了:我只是删除了将“autoDestroy”参数设置为“false”的网格。 下面的固定代码。

var myStore = new Ext.data.Store({ 
reader: new Ext.data.JsonReader({fields: MyRecord}), 
listeners:{ 
    'clear': function(store, recs) { 
    myTabPanel.remove(myGrid, false); 
    }, 
    'remove': function(store, rec, idx) { 
    if (store.getCount() == 0) { 
    myTabPanel.remove(myGrid, false); 
    } 
    } 
} 
}); 

var myGrid = new Ext.grid.GridPanel({ 
id: "myGrid", 
title: "A Grid", 
store: myStore, 
frame:false, 
border:false, 
columns: [ 
{ 
    header: 'Remove', 
    align:'center', 
    width: 45, 
    sortable: false, 
    renderer: function(value, metaData, record, rowIndex, colIndex, store) { 
    return '<img src="images/remove.png" width="34" height="18"/>'; 
    } 
},{ 
    header: 'Some Data', 
    dataIndex: 'data', 
    sortable: true 
} 
], 
listeners:{ 
    'cellclick':function(grid, rowIndex, colIndex, e){ 
    var rec = myStore.getAt(rowIndex); 
    if(colIndex == 0){ 
    myStore.remove(rec); 
    } 
    } 
} 
}); 

var myTabPanel= new Ext.TabPanel({ 
activeTab: 0, 
items: [ fooPanel, barPanel, myGrid] 
}); 
0

任何原因,你在物理上的标签去掉网格?看起来像一个奇怪的UI范例 - 为什么不只是用一个“空”的消息保持空格?

无论如何,我认为你的方法(使用商店事件和记录计数来确定何时删除它)基本上可以。你可能想弄清楚如何解决你所说的任何错误。他们是什么?