Results 1 to 7 of 7

Thread: GroupSummary: count

  1. #1
    Sencha User
    Join Date
    Dec 2009
    Posts
    425

    Question GroupSummary: count

    Hi,
    I am using a GroupSummary plugin with GridPanel.
    My situation is this....
    My store has a field called action. It can have one of the following values: 1,2,3,4.

    In my grid, i show 4 columns and based on the value of the field, i place an image in one of the columns. So any row will have only one image in one of the 4 columns. This much i have achieved.

    Now in the summary row, i want to show the count of images for each column.
    How to do this?

    doing this.... gives 4 always

    {header: "<b>1</b>", width: 50, dataIndex: 'action', sortable: true,
    renderer:
    function(value, metaData, record, rowIndex, colIndex, store)
    {
    if(value == 'Rating 1') metaData.attr = 'ext:qtip="Rating 1" style="background-image:url(../../Images/rating1.png) !important"';}
    ,
    summaryType:
    'count', summaryRenderer: function(v, params, data){
    return v;
    }, align:
    'center'}

    Please help



  2. #2
    Sencha User bclinton's Avatar
    Join Date
    Nov 2007
    Posts
    305

    Default

    I've never used the GroupSummary plug-in myself, but if you look at the source code for the example here: http://www.extjs.com/deploy/dev/exam...id/totals.html , you will see a custom summary function defined for the cost field.

    I think you need to define custom summary functions for your columns and specify them in the column configuration using the 'summaryType' config option.

    (also, please put code in code tags when you post so it is readable)

  3. #3
    Sencha User
    Join Date
    Dec 2009
    Posts
    425

    Default

    Thanks bclinton.
    I tried that but it didn't work. The problem is that the same field of my store is used as dataIndex for 4 different columns in the view

  4. #4
    Sencha User bclinton's Avatar
    Join Date
    Nov 2007
    Posts
    305

    Default

    The custom summary function has access to the record so I don't see why you couldn't do anything there that you aren't already doing in your custom column renderer.

  5. #5
    Sencha User
    Join Date
    Dec 2009
    Posts
    425

    Default

    Hi bclinton
    Because the same field of the store is used as dataIndex for 4 columns of the grid, the sum (summaryType) is calculated wrongly.
    I guess each column has to mapped to a different store column to get the correct sum.

  6. #6
    Sencha User bclinton's Avatar
    Join Date
    Nov 2007
    Posts
    305

    Default

    Quote Originally Posted by raj_plays View Post
    Hi bclinton
    Because the same field of the store is used as dataIndex for 4 columns of the grid, the sum (summaryType) is calculated wrongly.
    I guess each column has to mapped to a different store column to get the correct sum.
    Perhaps I don't understand completely, but I don't agree. You don't want a sum - you want a count. You want a count of a specific condition that you defining yourself. Since this is the case as I understand it, I don't see why you think your custom summary function can just be

    return v
    when your custom column renderer looks like this:
    Code:
    if(value == 'Rating 1') metaData.attr = 'ext:qtip="Rating 1" style="background-image:url(../../Images/rating1.png) !important"';
    You don't think you need some version of the same logic in your summary function? Maybe something like this?

    Code:
    return v + (value == 'Rating 1' ? 0:1);
    That's just a guess of what you are trying to do because you didn't post much code

  7. #7
    Sencha User
    Join Date
    Dec 2009
    Posts
    425

    Default

    bclinton,
    Thank you for replying to my queries.
    I have solved the problem. I will mention what I did and also attach a screenshot.
    The data of columns 1,2,3,4,5 all come from the same DB column.
    So i had to change my sql and my store in a way that each column is treated as a separate DB column.....

    Rate = Ext.data.Record.create([
    {name:
    'R1', type: 'int'},
    {name:
    'R2', type: 'int'},
    {name:
    'R3', type: 'int'},
    {name:
    'R4', type: 'int'},
    {name:
    'R5', type: 'int'},
    ......
    ]);

    and my grid has...

    {header: "<b>1</b>", width: 50, dataIndex: 'R1', sortable: true,
    renderer:
    function(value, metaData, record, rowIndex, colIndex, store)
    {
    if(value == 1) metaData.attr = 'ext:qtip="Rating 1" style="background-image:url(../../Images/rating1.png) !important"';}
    , summaryType:
    'sum', summaryRenderer: function(v, params, data){
    return v;
    }, align:
    'center'}

    similar config for the rest of the 4 columns

    And there is an custom function for the total column.

    Attached Images Attached Images

Posting Permissions

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