-
20 Mar 2012 4:22 PM #1
nested data into xtemplate dataview example using extjs 4.0.7 with MVC
nested data into xtemplate dataview example using extjs 4.0.7 with MVC
Hi Guys,
i was finally able to use nested data in xtemplate dataview overriding three functions
of the abstractview in the version 4.0.7 of extjs taking the implementation
from the release candidate 4.1 and the implementation of the update indexes
from a forum in internet because the one on the RC is not perfect.
Code:Ext.Loader.setConfig({enabled: true}); Ext.override(Ext.view.AbstractView, { prepareData: function(data, index, record) { var associatedData, attr; if (record) { associatedData = record.getAssociatedData(); for (attr in associatedData) { if (associatedData.hasOwnProperty(attr)) { data[attr] = associatedData[attr]; } } } return data; } }); Ext.override(Ext.view.AbstractView, { collectData : function(records, startIndex){ var data = [], i = 0, len = records.length, record; for (; i < len; i++) { record = records[i]; data[i] = this.prepareData(record.data, startIndex + i, record); } return data; }, // private bufferRender : function(records, index){ var me = this, div = me.renderBuffer || (me.renderBuffer = document.createElement('div')); me.tpl.overwrite(div, me.collectData(records, index)); return Ext.query(me.getItemSelector(), div); } }); Ext.override(Ext.view.AbstractView, { // private updateIndexes : function(startIndex, endIndex) { var ns = this.all.elements, records = this.store.getRange(); startIndex = startIndex || 0; endIndex = endIndex || ((endIndex === 0) ? 0 : (ns.length - 1)); for(var i = startIndex; i <= endIndex; i++){ ns[i].viewIndex = i; ns[i].viewRecordId = ((records.length > i) && records[i]) ? records[i].internalId : undefined; if (!ns[i].boundView) { ns[i].boundView = this.id; } } } });Last edited by mitchellsimoens; 21 Mar 2012 at 6:41 AM. Reason: added [CODE] tags
-
21 Mar 2012 6:42 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,121
- Vote Rating
- 453
Why didn't you use one Ext.override instead of 3?
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
21 Mar 2012 6:45 AM #3
I am not fond with javascript
i am making my first moves with extjs that's why
i used 3 overrides......
-
13 Dec 2012 7:57 AM #4
Thanks for the code. This is exactly what I was just looking for. Unfortunately the dataview does not update correctly after manipulating the store (deleting, updating records, ...).
Do you have any idea how this could be solved?
Maybe you can have a look at this thread I just started where i describe the problem a little more in detail.
Thanks & best regards,
Mike


Reply With Quote