Results 1 to 3 of 3

Thread: [FIXED-357][2.x/3.x] Element.insertSibling 'after' with array adds in invalid order

  1. #1
    Ext JS Premium Member
    Join Date
    Oct 2007
    Location
    Herndon, VA
    Posts
    265
    Vote Rating
    4
      0  

    Default [FIXED-357][2.x/3.x] Element.insertSibling 'after' with array adds in invalid order

    I was using a DataView bound to a store. If we added multiple records in the store (appended at last), the elements were displaying in wrong order in the DataView. After a little trace, I found that the main culprit seems to be insertSibling method of Ext.Element. If you pass an array, it adds elements one by one resulting the elements being added in reverse order. For this I applied the following fix:

    Code:
    Ext.override(Ext.Element, {
    	insertSibling: function (el, where, returnDom) {
    		var rt;
    		if (Ext.isArray(el)) {
    			// Fix: if where == 'after', it inserts at wrong position
    			var insertEl = this;
    			for (var i = 0, len = el.length; i < len; i++) {
    				rt = insertEl.insertSibling(el[i], where, returnDom);
    				if (where == 'after') {
    					insertEl = Ext.get(rt);
    				}
    			}
    			return rt;
    		}
    		where = where ? where.toLowerCase() : 'before';
    		el = el || {};
    		var refNode = where == 'before' ? this.dom : this.dom.nextSibling;
    
    		if (el.nodeType || el.dom) { // dh config
    			rt = this.dom.parentNode.insertBefore(Ext.getDom(el), refNode);
    			if (!returnDom) {
    				rt = Ext.get(rt);
    			}
    		} else {
    			if (where == 'after' && !this.dom.nextSibling) {
    				rt = Ext.DomHelper.append(this.dom.parentNode, el, !returnDom);
    			} else {
    				rt = Ext.DomHelper[where == 'after' ? 'insertAfter' : 'insertBefore'](this.dom, el, !returnDom);
    			}
    		}
    		return rt;
    	}
    });

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    118
      0  

    Default

    Or you could insert them in reverse order:
    Code:
    Ext.apply(Ext.Element.prototype, function() {
        var GETDOM = Ext.getDom,
            GET = Ext.get,
            DH = Ext.DomHelper;
        return {
            insertSibling: function(el, where, returnDom){
                var me = this,
                    rt;
                where = (where || 'before').toLowerCase();
                if(Ext.isArray(el)){
                    for(var i = 0, len = el.length; i < len; i++){
                        rt = me.insertSibling(el[where == 'before' ? i : len - 1 - i], where, returnDom);
                    }
                    return rt;
                }
                el = el || {};
                if(el.nodeType || el.dom){
                    rt = me.dom.parentNode.insertBefore(GETDOM(el), where == 'before' ? me.dom : me.dom.nextSibling);
                    if (!returnDom) {
                        rt = GET(rt);
                    }
                }else{
                    if (where == 'after' && !me.dom.nextSibling) {
                        rt = DH.append(me.dom.parentNode, el, !returnDom);
                    } else {
                        rt = DH[where == 'after' ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);
                    }
                }
                return rt;
            }
        };
    }());

  3. #3
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,436
    Vote Rating
    859
      0  

    Default

    This is fixed in SVN, both branches.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Posting Permissions

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