ExtJS: remove a grid from a tabpanel when its underlying store is empty

Posted by Antonio on Stack Overflow See other posts from Stack Overflow or by Antonio
Published on 2010-03-08T16:26:03Z Indexed on 2010/03/08 16:36 UTC
Read the original article Hit count: 982

Filed under:
|
|
|

Hi,

I have TabPanel which contains, among other things, a Grid connected to a Store.

Several events may remove elements from the store.

I would like the Grid to be removed from the TabPanel when the store is empty and, possibly, to have a single place in my code to check for this event.

I thought about using store listeners, but unfortunately this causes exceptions in Ext code. My assumption is that this happens because rendering is performed on the grid after this is removed from the tabpanel.

Any idea on how to accomplish such a task without messing up Ext is much appreciated. Thanks :)

By the way, this is a code excerpt:

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]
});

© Stack Overflow or respective owner

Related posts about extjs

Related posts about JavaScript