PDA

View Full Version : Extending Grid Feature?



haochi
12 Nov 2014, 6:47 PM
Hi,

I am trying to extend Grid summary feature but it's throwing an error


Uncaught TypeError: Cannot read property 'childNodes' of null

Here's the code sample, modified from http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.grid.feature.Summary




Ext.define('TestResult', { extend: 'Ext.data.Model', fields: ['student', { name: 'mark', type: 'int' }]});Ext.define('Ext.grid.feature.Summary2', { extend: 'Ext.grid.feature.Summary', alias: 'feature.summary2'});Ext.create('Ext.grid.Panel', { width: 400, height: 200, title: 'Summary Test', style: 'padding: 20px', renderTo: document.body, features: [{ ftype: 'summary2' }], store: { model: 'TestResult', data: [{ student: 'Student 1', mark: 84 }, { student: 'Student 2', mark: 72 }, { student: 'Student 3', mark: 96 }, { student: 'Student 4', mark: 68 }] }, columns: [{ dataIndex: 'student', text: 'Name', summaryType: 'count', summaryRenderer: function(value, summaryData, dataIndex) { return Ext.String.format('{0} student{1}', value, value !== 1 ? 's' : ''); } }, { dataIndex: 'mark', text: 'Mark', summaryType: 'average' }]});

carol.ext
13 Nov 2014, 9:28 AM
The summary feature has the view look it up in one of its functions using view.findFeature('summary');


renderTFoot: function(values, out) {
var view = values.view,
me = view.findFeature('summary');

if (me.showSummaryRow) {
out.push('<tfoot>');
me.outputSummaryRecord(me.createSummaryRecord(view), values, out);
out.push('</tfoot>');
}
},

Including that function in the summary2 feature updating the lookup to 'summary2' made it work, although less than optimal.


Ext.define('Ext.grid.feature.Summary2', {
extend: 'Ext.grid.feature.Summary',
alias: 'feature.summary2',

renderTFoot: function(values, out) {
var view = values.view,
me = view.findFeature('summary2');

if (me.showSummaryRow) {
out.push('<tfoot>');
me.outputSummaryRecord(me.createSummaryRecord(view), values, out);
out.push('</tfoot>');
}
}

});

I looked at the 5.01 code and the same lookup is in there, just in a different function (renderSummaryRow).