PDA

View Full Version : Getting Exception in plugin



newusername
10 Feb 2014, 5:12 AM
Hi I have developed a plugin for column's autowidth on grid , but it throwing me some exception. I am not able to understand why it is happening though. Please suggest

Plugin is as follow :



Ext.define('my.ColumnAutoWidth', {
extend : 'Ext.AbstractPlugin',
alias : 'plugin.columnautowidth',

constructor : function(config) {
console.log("columnAutoWidth Plugin");
},

init : function(grid) {
console.log("columnAutoWidth Plugin init method");
var view = grid.getView();
view.on('refresh',this.autoSize1(grid));

},

autoSize1 : function(grid){
console.log("here");
var columns = grid.columns, length = columns.length, i;
//var view = grid.view;
for (i = 0; i < length; i++) {
grid.view.autoSizeColumn(columns[i]);
}
}

});




normal html file where plugin is used



<script type="text/javascript">
Ext.onReady(function(){
Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', 'phone'],
data:{'items':[
{ 'name': 'Lisaa', "email":"lisa@simpsons.com", "phone":"555-111-1224" },
{ 'name': 'Bart', "email":"bart@simpsons.com", "phone":"555-222-1234" },
{ 'name': 'Homerrtsdfsdfsdfsdfsdfsfdfsfdfsfdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdfsdf', "email":"home@simpsons.com", "phone":"555-222-1244" },
{ 'name': 'Margefghjsfsdfsfsdfdsfsdfsdfsdfsdfsdfsdfsdf', "email":"marge@simpsons.comfsdsdfsdfsdfsdfsfsdfs", "phone":"555-222-125412345545245242342342342342342342342342434" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});

Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
//autoScroll : true,
//overflowY: 'scroll',
//overflowX: 'scroll',
columns: [
{ text: 'Name', dataIndex: 'name'},
{ text: 'Email', dataIndex: 'email'},
{ text: 'Phone', dataIndex: 'phone'}
],
height: 200,
width: 200,
margin : 20,
plugins : ['columnautowidth'],
renderTo: Ext.getBody()
});
});

jay@moduscreate.com
10 Feb 2014, 7:41 AM
Your problem is here:

view.on('refresh',this.autoSize1(grid));

it should be

view.on('refresh',this.autoSize1, this);

You're going to get other exceptions because your code is not 100%.

newusername
11 Feb 2014, 2:59 AM
Thanks for your reply. But please please correct me if I am wrong