PDA

View Full Version : GroupSummary: count



raj_plays
23 Feb 2010, 11:58 AM
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

bclinton
23 Feb 2010, 1:02 PM
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/examples/grid/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)

raj_plays
23 Feb 2010, 9:38 PM
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

bclinton
24 Feb 2010, 12:01 AM
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.

raj_plays
24 Feb 2010, 11:55 AM
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.

bclinton
24 Feb 2010, 2:38 PM
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 vwhen your custom column renderer looks like this:


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?


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

raj_plays
26 Feb 2010, 2:59 AM
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.