Grid with ServerAggregates Example

6 posts, 0 answers
  1. Keith
    Keith avatar
    12 posts
    Member since:
    Sep 2011

    Posted 26 Aug 2015 Link to this post

    Do you have an example of using the Kendo Grid control for javascript that sets the options to serverAggregates = true?  I have been trying to make this work and sadly only can get the client aggregation working.  I have read numerous configuration settings and other forums that make suggestions.  An example would be more affective showing both the data source options and the grid options working together.
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 28 Aug 2015 Link to this post

    Hello Keith,

    Please find below the required information in order to enable the server aggregates. 

    schema.aggreates defines the field in the server response which contains the calculated aggregates.

    aggregate option defines what aggregate function must be calculated. Those functions will be send to server when read request is issued in order to instruct the server handler what data is required.

    In order to show aggregates from DataSource inside Grid footer you must define footerTemplate for the columns.

    Also I attached a sample project to illustrate the described approach. 

     

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Jeffrey
    Jeffrey avatar
    2 posts
    Member since:
    Jan 2015

    Posted 29 Oct 2015 in reply to Boyan Dimitrov Link to this post

    I was looking at this example and it doesn't quite work for me.  We are using the virtualization option on the grid and also doing custom paging.  I am not using the ToDatasourceResult functions to return from the controller.

    var result = new DataSourceResult

    {
    Data = data,
    Total = pager.TotalRows
    };

    There is a property on the DataSourceResult that is called AggregateResults but man, I can't figure out how to set that.  Can't seem to find any examples of this property being set and how to set it.  Are there any examples of this somewhere?

    Here is my entire controller method so you can see in what context I am using this.  Appreciate any assistance you can provide.

    public ActionResult SearchAccounts([DataSourceRequest] DataSourceRequest request, HouseholdAccountSearchCriteria searchCriteria)
    {
        var pager = TrustHelper.GetPagerFromKendoRequest(request);
        var orderBy = TrustHelper.GetSortFromKendoRequest(request);
     
        var data = _householdService.SearchAccounts(searchCriteria, orderBy, null);
     
        var result = new DataSourceResult
        {
            Data = data,
            Total = pager.TotalRows,
            AggregateResults = ??
        };
     
        return Json(result);
    }

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 02 Nov 2015 Link to this post

    Hello Jeffrey,

    In case of creating the DataSourceResult without using the ToDatasourceResult method all calculations should be done manually. 

    I am afraid that we do not have any sample that shows the AggregateResults calculations. My suggestion is to use the project from my last post and inspect the DataSourceResult object after calling the ToDatasourceResult method. This will help you to determine what data and format should be used for the AggregateResults field. 

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  6. Jeffrey
    Jeffrey avatar
    2 posts
    Member since:
    Jan 2015

    Posted 04 Nov 2015 in reply to Boyan Dimitrov Link to this post

    Well, that sounds easy enough lol.  You can't create what that result looks like because most all the properties on the AggregateResult class ​are read only.  I need to set the Member that the aggregate is for and I can't figure out how to do that.  The constructor takes a value and a function, but no where I can tell it what member.  Any help would be appreciated.

    I guess for now I am just going to put some script on the client to set the footer values.  Would be nice to know how to do this properly on the server.

     Thanks

     

    var aggregateResults = new List<AggregateResult>();
    var agResult = new AggregateResult(123, new SumFunction());
    agResult.Member = ??
    aggregateResults.Add(agResult);

  7. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 06 Nov 2015 Link to this post

    Hello Jeffrey,

     

     

    Indeed the Member property is read-only, because it should be set using the AggregateFunction. The SourceField is the name of the field, which value is used as the argument of the aggregate function. 

     

    Regards,
    Boyan Dimitrov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready