Results 1 to 4 of 4

Thread: nested data into xtemplate dataview example using extjs 4.0.7 with MVC

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    56
    Vote Rating
    2
      1  

    Default 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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •