Completed
Last Updated: 20 May 2022 14:16 by ADMIN
Release 2022.R2.SP.next
Akesh Gupta
Created on: 14 Apr 2020 17:02
Category: UI for ASP.NET Core
Type: Feature Request
2
DataSource with aggregates and aspnetmvc-ajax does not support camel case names

kendo.aspnetmvc.js does not account for server aggregates serialized with came case property names like it does for Groups.

Can the following code (minus the comments) be included in a future release to resolve this?

function translateAggregateResults(aggregate) {
            var obj = {};
            // LSS: support for camel case serialization
            obj[(aggregate.AggregateMethodName || aggregate.aggregateMethodName).toLowerCase()] = (aggregate.Value || aggregate.value);
            return obj;
        }
        function translateAggregate(aggregates) {
            var functionResult = {}, key, functionName, aggregate;
            for (key in aggregates) {
                functionResult = {};
                aggregate = aggregates[key];
                for (functionName in aggregate) {
                    functionResult[functionName.toLowerCase()] = aggregate[functionName];
                }
                aggregates[key] = functionResult;
            }
            return aggregates;
        }
        function convertAggregates(aggregates) {
            var idx, length, aggregate;
            var result = {};
            for (idx = 0, length = aggregates.length; idx < length; idx++) {
                aggregate = aggregates[idx];
                // LSS: support for camel case serialization
                result[(aggregate.Member || aggregate.member)] = extend(true, result[(aggregate.Member || aggregate.member)], translateAggregateResults(aggregate));
            }
            return result;
        }
        extend(true, kendo.data, {
            schemas: {
                'aspnetmvc-ajax': {
                    groups: function (data) {
                        return $.map(this._dataAccessFunction(data), translateGroup);
                    },
                    aggregates: function (data) {
                        data = data.d || data;
                        // LSS: support for camel case serialization
                        var aggregates = data.AggregateResults || data.aggregateResults || [];
                        if (!$.isArray(aggregates)) {
                            for (var key in aggregates) {
                                aggregates[key] = convertAggregates(aggregates[key]);
                            }
                            return aggregates;
                        }
                        return convertAggregates(aggregates);
                    }
                }
            }
        });

3 comments
ADMIN
Ianko
Posted on: 16 Apr 2020 05:49

Hi Akesh,

I checked again the implementation provided. Indeed it looks safe and it should not break the internal usage of the aggregate mechanism in the DataSource utility.

I transformed the ticket to a feature request so that the request can be included in the product planning based on the demand. Due to other tasks that are already planned for the upcoming releases I am unable to provide a firm estimation when this will be included on the Kendo UI code. 

Regards,
Ianko
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Akesh Gupta
Posted on: 15 Apr 2020 14:59
How could checking for the other cases break anything? You are already doing this check for the Groups in your translateGroup function, Why only have partial support for properly serialized JSON? 

Can you detail the breaking changes so that I can make sure I am not overlooking any issues caused in my application due to this change?
ADMIN
Ianko
Posted on: 15 Apr 2020 10:34

Hi Akesh,

Changing the code internally will cause a breaking change in how Aggregates works with the internal DataSource utility. In both MVC and Core suites.

The solution for your case is to either:

Regards,
Ianko
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.