Results 1 to 4 of 4

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

  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

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,323
    Vote Rating
    1294
      0  

    Default

    Why didn't you use one Ext.override instead of 3?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    56
    Vote Rating
    2
      0  

    Default

    I am not fond with javascript
    i am making my first moves with extjs that's why
    i used 3 overrides......

  4. #4
    Sencha User
    Join Date
    Mar 2012
    Posts
    129
    Vote Rating
    1
      0  

    Default

    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

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
  •