120
Customizing groupedRowTextTemplate for iggrid to include sum of non-key column
posted

Hi,

I am using a grid with groupby to display data. I have search both this forum and on the net for a solution but have not found anything that makes me able to accomplice what I am after.

My grid have a number of columns and grouping in multiple levels works as intended. One column has the field of "Amount", which is 1 or more for each data row. Using the summary functions, I can easily get the sum of "Amounts" for each group of rows.

groupedRowTextTemplate defines the text for the grouped row header and I want to alter this to include the sum value of the "Amount" column. This would allow me to show the most important information with the grouped rows collapsed.

I guess I need some jquery/JavaScript in order to make this work, but I am not sure how to do this.

I am working in MVC using the wrapper to create my grid.

/ FW

  • 0
    Offline posted

    Hello Fredrik,
    By design igGrid provides summaries within Group By feature, which can be set in columnSettings collection. This can be set via summaries option for each column. This option is a list of aggregations functions to calculate on the column values for each group. For example:

     @(Html.Infragistics()
                    .Grid(Model)
                    .ID("products")
                    .Width("100%")
                    .Height("500px")
                    .PrimaryKey("ID")
                    .AutoGenerateColumns(false)
                    .AutoGenerateLayouts(false)
                    .AutoFormat(GridAutoFormat.DateAndNumber)
                    .Columns(column =>
                    {
                        column.For(x => x.ProductName).HeaderText("Product Name").Width("40%");
                        column.For(x => x.Rating).HeaderText("Amount").Width("60%");
                    })
                    .Features(features =>
                    {
                        features.GroupBy().Type(OpType.Remote).GroupByUrlKeyAscValue("asc").GroupByUrlKeyDescValue("desc").GroupByUrlKey("groupBy").ColumnSettings(cs =>
                        {
                            cs.ColumnSetting().ColumnKey("Amount").Summaries(gs => {
                                gs.Summary().Text("Amount sum: ").SummaryFunction(SummaryFunction.Sum);
                            });
                        });
                    })
                    .DataSourceUrl(Url.Action("GetData1"))
                    .ResponseDataKey("Records")
                    .Render()
            )


    Please test it on your side and let me know if you need any further assistance with this matter.

    Best Regards,
    Martin Kamenov
    Associate Software Developer
    Infragistics, Inc.

  • 120
    Offline posted

    With the help from Martin Kamenov, I have found a way to achieve what I wanted. The trick was to add the summarysettings part and Summaries to the "Amount" column.

    features.GroupBy()

    .SummarySettings(new GroupBySummarySettings() { SummaryFormat = "#0" })

    .GroupSummariesPosition(GroupSummariesPositionMode.Top)

    .InitialExpand(false)

    .ColumnSettings(groupedcolumn =>

    {

    groupedcolumn.ColumnSetting().ColumnKey("ID").IsGroupBy(true);

    groupedcolumn.ColumnSetting().ColumnKey("Amount").Summaries(s =>

    {

    s.Summary().Text("total: ").SummaryFunction(SummaryFunction.Sum);

    }).GroupSummaries(gs =>

    {

    gs.GroupSummary().SummaryFunction(SummaryFunction.Count);

    gs.GroupSummary().SummaryFunction(SummaryFunction.Sum);

    });

    });

    This adds "Amount total: n" to the grouped row text, which makes the total amount visible even when the grouped row is collapsed.

    It seems to work as intended, so thanks for the help!