Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Apr 2011
    Location
    Northern Virginia
    Posts
    15
    Vote Rating
    0
    trebor is on a distinguished road

      0  

    Default Problem dynamically adding records to GroupingStore

    Problem dynamically adding records to GroupingStore


    See attached example (drop in examples/grid folder).

    When I add a new record to the store, a new group is created, instead of adding the record to an existing group.

    To reproduce problem with attached example, do the following:

    1. click "New A" (new group A is created)
    2. click "New B" (new group B is created)
    3. click "New A" (a second group A is created instead of adding the new record to the existing group A)

    This problem is not a problem in 4.0, but it is a problem in all previous versions (3.4, 2.3, 2.2, etc.).

    Thanks!

    Note: if you click "New A" twice it works as expected - on breaks down when switching between groups.
    Attached Files

  2. #2
    Sencha User
    Join Date
    Apr 2011
    Location
    Northern Virginia
    Posts
    15
    Vote Rating
    0
    trebor is on a distinguished road

      0  

    Default


    Here is a fix for this:

    Code:
    Ext.override(Ext.grid.GroupingView, {
    
    
        doRender: function (cs, rs, ds, startRow, colCount, stripe) {
            if (rs.length < 1) {
                return '';
            }
            var groupField = this.getGroupField();
            var colIndex = this.cm.findColumnIndex(groupField);
    
    
            this.enableGrouping = !!groupField;
    
    
            if (!this.enableGrouping || this.isUpdating) {
                return Ext.grid.GroupingView.superclass.doRender.apply(
                        this, arguments);
            }
            var gstyle = 'width:' + this.getTotalWidth() + ';';
    
    
            var gidPrefix = this.grid.getGridEl().id;
            var cfg = this.cm.config[colIndex];
            var groupRenderer = cfg.groupRenderer || cfg.renderer;
            var prefix = this.showGroupName ?
                         (cfg.groupName || cfg.header) + ': ' : '';
    
    
            var groups = [], curGroup, i, len, gid;
            for (i = 0, len = rs.length; i < len; i++) {
                var rowIndex = startRow + i;
                var r = rs[i],
                    gvalue = r.data[groupField],
                    g = this.getGroup(gvalue, r, groupRenderer, rowIndex, colIndex, ds);
    
    
                // fix
                if (!curGroup || curGroup.group != g) {
                    curGroup = null;
                    for (var j = 0; j < groups.length; j++) {
                        if (groups[j].group == g) {
                            curGroup = groups[j];
                        }
                    }
                }
                // fix
    
    
                if (!curGroup) {
                    gid = gidPrefix + '-gp-' + groupField + '-' + Ext.util.Format.htmlEncode(g);
                    // if state is defined use it, however state is in terms of expanded
                    // so negate it, otherwise use the default.
                    var isCollapsed = typeof this.state[gid] !== 'undefined' ? !this.state[gid] : this.startCollapsed;
                    var gcls = isCollapsed ? 'x-grid-group-collapsed' : '';
                    curGroup = {
                        group: g,
                        gvalue: gvalue,
                        text: prefix + g,
                        groupId: gid,
                        startRow: rowIndex,
                        rs: [r],
                        cls: gcls,
                        style: gstyle
                    };
                    groups.push(curGroup);
                } else {
                    curGroup.rs.push(r);
                }
                r._groupId = gid;
            }
    
    
            var buf = [];
            for (i = 0, len = groups.length; i < len; i++) {
                var g = groups[i];
                this.doGroupStart(buf, g, cs, ds, colCount);
                buf[buf.length] = Ext.grid.GroupingView.superclass.doRender.call(
                        this, cs, g.rs, ds, g.startRow, colCount, stripe);
    
    
                this.doGroupEnd(buf, g, cs, ds, colCount);
            }
            return buf.join('');
        }
    
    
    });

  3. #3
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Stockholm, Sweden
    Posts
    2,713
    Vote Rating
    104
    mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all mankz is a name known to all

      0  

    Default


    This is not a bug, just how the GroupingStore works. After an add, you must call groupBy.

    Code:
    store.groupBy(someField, true);

  4. #4
    Sencha User
    Join Date
    Apr 2011
    Location
    Northern Virginia
    Posts
    15
    Vote Rating
    0
    trebor is on a distinguished road

      0  

    Default


    Thanks - I'll give that a try.

Thread Participants: 1