doubleA
doubleA

Reputation: 11

Cannot get the object of a tabpanel

I have a grid in the center region of a border layout. When a specific item is clicked in the grid, I need to change the center region to display a tab panel. I am having trouble getting the tabpanel object.

In the ctrlpanel file, on the grid listener, I am using componentQuery to get the tabpanel('ccmain') object. It returns undefined.

I was using componentQuery to get 'ccmain' in the centerpanel file(lays out center region) successfully, but when I moved this code to the ctrlpanel file(one of the items in centerpanel) it fails. ComponentQuery no longer returns the tabpanel 'ccmain'. ComponentQuery does return the centerpanel or the viewport. I attemped to do centerpanel or viewport.down to find 'ccmain', but that also returns undefined. If you can tell me how to get the tabpanel or what I am doing wrong, I would appreciate it. Thanks for your time.

ctrlPanel.js

Ext.define('ServcSol.view.CtrlPanel',{
extend: 'Ext.Panel',

alias: 'widget.ctrlPanel',
xtype: 'ctrlPanel',
itemId: 'ctrlPanel',

requires:[
    'ServcSol.store.FacilityStore'
    ],

initComponent: function () {  

var me = this;

Ext.applyIf(me, {

items: [ 
{
  xtype: 'panel',
  height: 750,
  title: 'Control Panel',
  items: [
  {
   xtype: 'gridpanel',
   padding: '20 20 5 20',
   store: 'WorkHistoryStore',
   height: 590,
   width: '100%',
   border: true,
   columns: [
   {
     width: 110,
     dataIndex: 'wrkhistDate',
     text: 'Due Date'
   },
   {
     width: 100,
     dataIndex: 'wrkType',
     text: 'Work Type'
   }
 ], 
 listeners : {
   itemclick: function(dv, record, item, index, e) 
   {
     if(record.get('wrkType') == 'Test')
         {                   
           var tabPanel = Ext.ComponentQuery.query('ccmain')[0];
           console.log('tabPanel is: ', tabPanel);
           var tabIndex = tabPanel.items.findIndex('id', 'hazard');
           var center = Ext.ComponentQuery.query('centerpanel')[0];
           center.getLayout().setActiveTab(tabIndex);
     }

ccmain.js

Ext.define('ServcSol.view.ccMain', {
extend: 'Ext.tab.Panel',
itemId: 'ccmain',
alias: 'widget.ccmain',
xtype: 'ccmain',

initComponent: function () {

var me = this;

Ext.applyIf(me, {
items: [
      {
        xtype: 'facility'
      },
      {
        xtype: 'hazListing'
      },
      {
        xtype: 'hazard'
      }, 
      {
        xtype: 'testFormRP'
      },
      {
        xtype: 'testFormDC'
      } 
       ]
    });      
  this.callParent(arguments);
  }
 });

Upvotes: 1

Views: 513

Answers (1)

Saki
Saki

Reputation: 5856

One of the reasons can be that ccmain is not instantiated as only instantiated components can be found by ComponentQuery.query. Then, even if ccmain would be found you cannot set its active item that way. Easiest is to assign tabs itemIds and then call setActiveTab:

tabPanel.setActiveTab(itemIdOfTheTab)

Upvotes: 0

Related Questions