You found a bug! We've classified it as EXTJS-10840 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Sencha Premium Member fl.borovsky's Avatar
    Join Date
    Jul 2013
    Posts
    73
    Vote Rating
    4
    fl.borovsky is on a distinguished road

      0  

    Default Strange behaviour while summary grouping grid by float/int field

    Strange behaviour while summary grouping grid by float/int field


    There is an implementation bug in Store class, I provide working solution for it:
    old extjs code:

    new code:

    reproduce bug:
    1. create model with number field
    2. create data with 3 records having that field equals to 0, 0.5, 1 respectively
    3. create grid panel with groupingsummary feature and group by that field

    expected result:

    given result:


    what is wrong? everywhere should be "count: 1" and where is last summary row? it disapeared.
    My explamation:
    1. Group creation process creates a map aggregated field -> group instance
    2. It iterates through all records and checks if the key from record exists in group-by-key map
    3. if groups.get(groupValue) is null, new group will be created, otherwise existing group will be fetched and record added to the group

    The problem is, that groups is a MixedCollection and there is get method used to check if group exists.
    Note that get method has two features: it looks for a key but if doesn't exist and the key is an number, the item at specified index (=key) will be returned

    Trace following example:
    three records with fields: 0, 0.5, 1
    below is pseudo code for each groups.get(groupValue) execution and next if(group){create new gruop} statement
    >>groups: empty array
    1. does gruop exist of key 0? no. 0 is number? yes. so return [0] which is undefined
    >>groups: [0: group of key 0]
    2. does group exist of key 0.5? no. 0.5 is number? yes. so return [0.5] which is not an index and is undefined
    >>groups: [0: group of key 0, 1: group of key 0.5]
    3. does group exist of key 1? no. 1 is number? yes so return [1] which exists and is group of key 0.5
    >>groups: [0: group of key 0, 1: group of key 0.5]

    so because of wrong usage of mixed collection api we created two groups instead of three and last record was assigned to second group instead of new-third

    As written in docs, getByKey method never tracks argument as index so it is safe in opposite to get() method.

    ---------

    Again:
    without my fix:

    with my fix:


    *EDIT BY SLEMMON
    Issue observed in 4.2.0 and 4.2.1. Tested OK in 4.1.3.

    Inline test case:
    Code:
    
    
    Code:
    Ext.define('TestResult', {
        extend: 'Ext.data.Model',
        fields: ['student', 'subject', {
            name: 'mark',
            type: 'number'
        }]
    });
    
    
    Ext.create('Ext.grid.Panel', {
        width: 200,
        height: 240,
        renderTo: document.body,
        features: [{
            groupHeaderTpl: 'Subject: {name}',
            ftype: 'groupingsummary'
        }],
        store: {
            model: 'TestResult',
            groupField: 'mark',
            data: [{
                student: 'Student 1',
                subject: 'Math',
                mark: 0
            },{
                student: 'Student 1',
                subject: 'Science',
                mark: .5
            },{
                student: 'Student 2',
                subject: 'Math',
                mark: 1
            }]
        },
        columns: [{
            dataIndex: 'student',
            text: 'Name'
        }, {
            dataIndex: 'mark',
            text: 'Mark',
            summaryType: 'count'
        }]
    });
    Last edited by slemmon; 2 Aug 2013 at 1:25 PM. Reason: additional test info

  2. #2
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,062
    Vote Rating
    215
    slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of slemmon has much to be proud of

      0  

    Default


    Thanks for the report! I have opened a bug in our bug tracker.

Thread Participants: 1

Tags for this Thread