ashhad
ashhad

Reputation: 173

Accessing 2nd tab of tabpanel

I m getting undefined values while accessing grid rows of 2nd tab of tabpanel.

I have created a tabpanel with the following code:

xtype: 'tabpanel',
border: false,
deferredRender: true,
region: 'center',
activeTab: 0,
items:[{
        id: 'availableoperators',
        itemId: 'ops-operators-grid',
        xtype: 'chat.dashboard.opsmall',
        title: 'Operators',
        region: 'center'
    }, {
        id: 'availableagents',
        itemId: 'ops-agents-grid',
        xtype: 'chat.dashboard.opsmgrid',
        title: 'Agents',
        region: 'center'
    }]

Here I m trying to access rows of 2nd panel:

var opsGrid = Ext.getCmp('availableagents');
var records = opsGrid.store.getRange(0, opsGrid.store.getTotalCount());
for(var i = 0; i < records.length; i++) {
    var row = opsGrid.getView().getRow(i);
}

The above code is working fine only if I use id of first tab. Any help would be appreciated.

Upvotes: 0

Views: 847

Answers (2)

Michael
Michael

Reputation: 1193

I'm going in the same way that Selmaril. Your view is not accessible. If you want, you can switch tab before the getView.

 yourTabPanel.setActiveTab("availableagents");
 yourTabPanel.doLayout();

Where yourTabPanel is the xtype: 'tabpanel', set it an id and you will be able to do: Ext.getCmp("yourTabPanel").setActiveTab("availableagents");

Upvotes: 0

Selmaril
Selmaril

Reputation: 766

It happens because component on the tab will be rendered at first shown. Store by default will be loaded after rendering of the grid on this tab. So you don't have rendered markup (the opsGrid.getView()) and don't have loaded data at store untill you opened the tab. If you will open second tab and manually run your code it should work fine.

Try to set deferredRender to false for the tabpanel, or forceLayout to true for your second tab. It will force rendering and loading all tabs (deferredRender:false) or only tab, there you will set forceLayout.

Upvotes: 1

Related Questions