PDA

View Full Version : Question about CheckboxModel in Grid



guyuanershi
11 Mar 2012, 9:02 AM
I have a closable tab, and it has a grid with CheckboxModel. If I wrote both 'tab' and 'grid' code in the same file, everything works fine. however, the grid is so big, so i need to have new file for the grid only.

Then the problem is coming, after closing the tab and open it again, the checkbox column of the grid disappeared. And there are some error messages like 'Uncaught TypeError: Cannot call method 'removeCls' of undefined'.

any hint?

part of grid?


Ext.define('MTest',{
extend: 'Ext.grid.Panel',
alias: 'widget.testpanel',
selModel: Ext.create('Ext.selection.CheckboxModel'),
store: getLocalStore(),
columns:[
{text: 'company', dataIndex: 'company', flex: 1},
{text: 'price', dataIndex: 'price', flex:1},
{text: 'change', dataIndex: 'change', flex:1}
]
});


part of tab?
[CODE]
var tabs = Ext.createWidget('tabpanel', {
renderTo: 'tabs',
resizeTabs: true,
enableTabScroll: true,
width: 600,
height: 250,
defaults: {
autoScroll:true,
bodyPadding: 10
},
items: [...]
});

/*create tab*/
function addTab () {
tabs.add({
title: 'New Tab ',
iconCls: 'tabs',
items:[{xtype:'testpanel'}],
closable: true
}).show();
}

/*button for adding tab*/
Ext.createWidget('button', {
renderTo: 'addButtonCt',
text: 'Add Closable Tab',
handler: function () {
addTab();
},
iconCls:'new-tab'
});

vietits
11 Mar 2012, 5:39 PM
You should not use objects on shared prototype of a class. Try to fix your code as below


Ext.define('MTest',{
extend: 'Ext.grid.Panel',
alias: 'widget.testpanel',
initComponent: function(){
var me = this;
Ext.apply(me, {
selModel: Ext.create('Ext.selection.CheckboxModel'),
store: getLocalStore(),
columns:[
{text: 'company', dataIndex: 'company', flex: 1},
{text: 'price', dataIndex: 'price', flex:1},
{text: 'change', dataIndex: 'change', flex:1}
]
});
me.callParent(arguments);
}
});

guyuanershi
12 Mar 2012, 11:10 PM
thanks