Dynamic Grid Columns and Aggregate Function

4 posts, 0 answers
  1. Abdullah Önden
    Abdullah Önden avatar
    20 posts
    Member since:
    Aug 2009

    Posted 04 Feb 2010 Link to this post

    Hello

    I have a Grid which generates its columns automatically. Grid's column counts changes with SQL. How can I add aggregate
    function to these dynamic columns? I'd like to show these in footer. Where should I control it, onitemdatabound or something?




  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 05 Feb 2010 Link to this post

    Hello Abdullah,

    Each auto-generated column causes the grid to trigger its ColumnCreated event where you can access the column (e.Column) and set its Aggregate function.

    I hope this helps.

    Best wishes,
    Tsvetoslav
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 15 Apr 2011 Link to this post

    Hi,

    Could you explain how I have this agregatefunction SumFunction in the Group Footer of the column which is a monetary column
    I should see something like $200 since I have 2 rows with the $100 each

    I tried this but there's nothing shown on the GROUP FOOTER

    void rgvTest_AutoGeneratingColumn(object sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
    {
        if(e.Column.UniqueName == "Property2")
            e.Column.AggregateFunctions.Add(new SumFunction() { Caption = "", ResultFormatString = "C2" });
    }
  5. Vipul
    Vipul avatar
    1 posts
    Member since:
    Mar 2016

    Posted 22 Mar Link to this post

    Hi,

    Here is the complete code for dyanmic grid with dynamic column and aggregate.

    $.ajax({
                    url: ",
                    datatype: "JSON",
                    type: "GET",
                    success: function (result) {
                        var items = $.parseJSON(result)[0];
                        var arrCol = [];
                        var arrAgg = [];
                        for (var index in items) 
    {
    arrCol.push({ field: index, format: "{0:0}", aggregates: ["sum"], footerTemplate: "#= kendo.toString(sum, '0.00') #" });
    arrAgg.push({ field: index, aggregate: "sum" });
                        }
                        console.log(arrAgg);
                        if (result.Result.length > 0) {
                            var dataSource = new kendo.data.DataSource({
                                data: $.parseJSON(result.Result),
                                group: { field: "Category" },
                                aggregate: arrAgg
                            });
                            $('#divgrid').html("");
                            $("#divgrid").kendoGrid({
                                dataSource: dataSource,
                                height: "auto",
                                scrollable: false,
                                sortable: true,
                                groupable: false,
                                columns: arrCol
                            });

     

     

Back to Top