PDA

View Full Version : templatecolumn doesn't work with data that contains a root



felipe.duarte
26 Jul 2012, 2:16 PM
Hi guys,

I'm trying to get data from a store in a grid using the templatecolumn xtype. In the docs the data example doesn't contain a root (which in my case I have) and when I modify the example on live code it doesn't work:


Ext.create('Ext.data.Store', { storeId:'employeeStore',
fields:['firstname', 'lastname', 'seniority', 'department'],
groupField: 'department',
data:[ { row: [
{ firstname: "Michael", lastname: "Scott", seniority: 7, department: "Management" },
{ firstname: "Dwight", lastname: "Schrute", seniority: 2, department: "Sales" },
{ firstname: "Jim", lastname: "Halpert", seniority: 3, department: "Sales" },
{ firstname: "Kevin", lastname: "Malone", seniority: 4, department: "Accounting" },
{ firstname: "Angela", lastname: "Martin", seniority: 5, department: "Accounting" }
]}
],
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'rows'
}
}
});


Ext.create('Ext.grid.Panel', {
title: 'Column Template Demo',
store: Ext.data.StoreManager.lookup('employeeStore'),
columns: [
{ text: 'Full Name', xtype: 'templatecolumn', tpl: '{firstname} {lastname}', flex:1 },
{ text: 'Department (Yrs)', xtype: 'templatecolumn', tpl: '{department} ({seniority})' }
],
height: 200,
width: 300,
renderTo: Ext.getBody()
});

Am I doing something wrong? Any ideas?

scottmartin
27 Jul 2012, 12:25 PM
Please try this:



Ext.create('Ext.data.Store', { storeId:'employeeStore',
fields:['firstname', 'lastname', 'seniority', 'department'],
groupField: 'department',
data:{'rows':[
{ firstname: "Michael", lastname: "Scott", seniority: 7, department: "Management" },
{ firstname: "Dwight", lastname: "Schrute", seniority: 2, department: "Sales" },
{ firstname: "Jim", lastname: "Halpert", seniority: 3, department: "Sales" },
{ firstname: "Kevin", lastname: "Malone", seniority: 4, department: "Accounting" },
{ firstname: "Angela", lastname: "Martin", seniority: 5, department: "Accounting" }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'rows'
}
}
});


Ext.create('Ext.grid.Panel', {
title: 'Column Template Demo',
store: Ext.data.StoreManager.lookup('employeeStore'),
columns: [
{ text: 'Full Name', xtype: 'templatecolumn', tpl: '{firstname} {lastname}', flex:1 },
{ text: 'Department (Yrs)', xtype: 'templatecolumn', tpl: '{department} ({seniority})' }
],
height: 200,
width: 300,
renderTo: Ext.getBody()
});
?

Scott.