This is a migrated thread and some comments may be shown as answers.

aggregate count undefined in mvc.ui.fluent

7 Answers 139 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kelso
Top achievements
Rank 1
Kelso asked on 08 Sep 2014, 09:52 PM
I have no idea what I am missing here, but no matter what I try, I cannot get the count to be accessible using #=count#  I have this working with JavaScript by using a function to return the count but this count should be accessible according to the demo examples which I have been over many times, and cannot see my mistake. Calling the "#=ClockInStatusString(data)#" and  #=groupHeaderString(data)# works fine, the proper data is returned.

<div>
            @(Html.Kendo().Grid<viewmodel>()
          .Name("CampaignGrid")
          .Columns(columns =>
          {
              columns.Bound(c => c.FirstName).Sortable(true);
              columns.Bound(c => c.LastName);
              columns.Bound(c => c.ClockInDate);
              columns.Bound(c => c.ClockInTime);
              columns.Bound(c => c.ClockInStatus).ClientTemplate("#=ClockIStatusString(data)#").ClientGroupHeaderTemplate("#=groupHeaderString(data)# #=count#");
              columns.Bound(c => c.Campaign).ClientGroupHeaderTemplate("(Agents Count: #=count# )"); ;
              columns.Bound(c => c.UserName).ClientTemplate("<a href='/User/GetUserHistory/#= UserName#'>Activity</a>");
          })
          .Sortable(sort => sort.Enabled(true))
          .DataSource(datasource => datasource
              .SignalR()
              .Aggregates(aggregates =>
              {
                  aggregates.Add(c => c.ClockInStatus).Count();
                  aggregates.Add(c => c.Campaign).Count();
              })
              .Group(groups =>
              {
                  groups.Add(model => model.ClockInStatus);
                  groups.Add(model => model.Campaign);
              })
              .Transport(tr => tr.Promise("hubPromise")
                  .Hub("hub")
                  .Server(server => server
                      .Read("getClockedInUsers")
                      .Update("update")
                      .Destroy("desstroy")
                      .Create("create")))
              .Schema(scheme => scheme
                  .Model(model =>
                  {
                      model.Id(c => c.UserId);
                      model.Field(c => c.FirstName);
                      model.Field(c => c.LastName);
                      model.Field(c => c.ClockInDate);
                      model.Field(c => c.ClockInTime);
                      model.Field(c => c.Campaign);
                      model.Field(c => c.ClockInStatus);
                      model.Field(c => c.UserId);
                  }))
              )
            )
        </div>

Any help would be appreciated!
Thanks!

7 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 11 Sep 2014, 06:45 AM
Hi Kelso,

Thank you for bringing this issue to our attention. The reason for current behavior is that the groups currently are not serialized correctly with the needed aggregates (it will be fixed in next internal builds).

Also you can use the workaround below until we get this issue fixed (place the code after the Grid initialization code):

$(function () {
    //rename the fields to match your model
    var fieldA = "Discontinued";
    var fieldB = "ProductName";
 
    var aggregateFieldA = {
        field: fieldA,
        aggregate: "count"
    };
 
    var aggregateFieldB = {
        field: fieldB,
        aggregate: "count"
    };
 
    var grid = $("#Grid").data("kendoGrid");
 
    var groups = grid.dataSource.group();
    for (var i = 0; i < groups.length; i++) {
        if (groups[i].field == fieldB) {
            groups[i].aggregates = [aggregateFieldB, aggregateFieldA];
        } else if (groups[i].field == fieldA) {
            groups[i].aggregates = [aggregateFieldA, aggregateFieldB];
        }
    }
 
    grid.dataSource.group(groups);
})

Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kelso
Top achievements
Rank 1
answered on 11 Sep 2014, 05:58 PM
ok, You have given me a javascript solution to a problem with mvc.ui.fluent syntax, that is fine but the javascript version I am using actually works, with one issue, some of the accounts come back as undefined, but not all of them. I am not sure if this is part of the same issue, or if it is something different, but your work around does not fix it. That said, I am not sure how to integrate the javascript workaround you gave me with the fluent syntax. I am going to post all of my javascript here in case this is a different issue. And would it be possible to show how to implement your work around integrated with existing syntax I have?

$(function() {

    var connection = $.hubConnection();
    var hub = connection.createHubProxy("centralHub");
    connection.logging = true;
    var hubPromise = connection.start();

    var columns = [
        {
            field: "FirstName",
            title: "First Name",
            filterable: false,
            width: "10%",
        },
        {
            field: "LastName",
            title: "Last Name",
            filterable: false,
            width: "10%",
        },
        {
            field: "ClockInDate",
            title: "Clock In date",
            format: "{0: MMMM dd, yyyy}",
            sortable: true,
            filterable: { ui: "datetimepicker" },
            width: "10%",
        },
        {
            field: "ClockInTime",
            title: "Clock In time",
            type: "date",
            format: "{00: hh:mm:ss tt}",
            sortable: true,
            filterable: { ui: "timepicker" },
            width: "10%",
            template: function(data) {
                var date = new Date(data.ClockInTime);
                var localOffSet = date.getTimezoneOffset() * 60000;
                var localTime = date.getTime();
                date = localTime - localOffSet;
                return new Date(date).toLocaleTimeString("en-US");
            }
        },
        {
            field: "Campaign",
            title: "Current Campaign",
            sortable: true,
            width: "10%",
            aggregates: ["count"],
            groupHeaderTemplate: function(data) {
                return data.value + " (Assigned Agents: " + data.count + ")";
            }
        },
        {
            field: "ClockInStatus",
            title: "Current Status",
            sortable: true,
            width: "10%",
            template: function (data) {
                var status = 0;
                switch (data.ClockInStatus) {
                case 1:
                    status = "Clocked in";
                    break;
                case 2:
                    status = "On Break";
                    break;
                case 3:
                    status = "On Lunch";
                    break;
                case 4:
                    status = "On Lockdown";
                    break;
                case 5:
                    status = "Institution Count";
                    break;
               case 6:
                   status = "Clocked Out";
                   break;
                default:
                    status = "Status Unknown";
                    break;
                }
                return status;
            },
            groupHeaderTemplate: function (data) {
                var status = 0;
                switch (data.value) {
                    case 1:
                        status = "Clocked in";
                        break;
                    case 2:
                        status = "On Break";
                        break;
                    case 3:
                        status = "On Lunch";
                        break;
                    case 4:
                        status = "On Lockdown";
                        break;
                    case 5:
                        status = "Institution Count";
                        break;
                    case 6:
                        status = "Clocked Out";
                        break;
                    default:
                        status = "Status Unknown";
                        break;
                }
                return status + " (Agent Count: " + data.count + ")";
            },
        },
        {
            title: "Activity History",
            width: "10%",
            template: function (data) {
                return "<a href='/User/GetUserHistory/" + data.UserName + "'>Activity</a>";
            }
        }
    ];
    var clockInGridTransport = {
        signalr: {
            promise: hubPromise,
            hub: hub,
            server: {
                read: "getClockedInUsers",
                update: "update",
                destroy: "destroy",
                create: "create"
            },
            client: {
                read: function (data, e) {

                },
                update: "update",
                destroy: "destroy",
                create: "create"
            }
        }
    }

    var clockinGridDataSource = {
        ServerOperation: false,
        type: "signalr",
        autoSync: false,
        schema: {
            model: {
                id: "UserId",
                fields: {
                    "UserId": { editable: false, nullable: false },
                    "UserName": { type: "string" },
                    "FirstName": { type: "string" },
                    "LastName": { type: "string" },
                    "ClockInDate": { type: "date" },
                    "ClockInTime": { type: "date" },
                    //"ClockOutDate": { type: "date" },
                    //"ClockOutTime": { type: "date"},
                    //"TotalClockTime": { type: "number" },
                    "Campaign": { type: "string" },
                    "Notes": { type: "string" },
                    //"IsEnrolled": { type: "boolean" },
                    "ClockInStatus": { type: "number" },
                    //"BiometricsRequired": { type: "boolean" },
                    "PendingReview": { type: "boolean" }

                }
            }
        },
        group: [
             {
                 field: "ClockInStatus",
                 aggregates: [{ field: "ClockInStatus", aggregate: "count" }]
             },
            {
                field: "Campaign",
                aggregates: [
                    { field: "Campaign", aggregate: "count" }
                ]
            }
        ],
        aggregate: [{ field: "ClockInStatus", aggregate: "count" },
                    { field: "Campaign", aggregate: "count" }],

        sort: [{ field: "ClockInTime", dir: "desc" }],
        transport: clockInGridTransport
    }

    $("#clockInGrid").kendoGrid({
        scrollable: true,
        editable: false,
        sortable: true,
        groupable: false,
        filterable: { model: "row" },
        columns: columns,
        dataSource: clockinGridDataSource
    });

   
    hub.on("refreshClient", function() {
        var grid = $("#clockInGrid").data("kendoGrid");
        grid.dataSource.read();
    });
});

0
Vladimir Iliev
Telerik team
answered on 12 Sep 2014, 07:40 AM
Hi Kelso,

Current behavior is not related to the previously reported issue. Also I tried to reproduce the issue on our side but to no avail - everything is working as expected (as seen in this demo). As current thread is getting out of the original topic, may I kindly ask you to open a new support thread for the Grid and provide runable example where the issue is reproduced? In this way it is much easier to follow and concentrate on the particular issue which usually leads to its faster resolving.

Kind Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kelso
Top achievements
Rank 1
answered on 12 Sep 2014, 02:10 PM
I did some research on this, and it is related to the same issue, the reason it comes back undefined, is that I am rendering the groupheader as a function, and that count aggregate does not exist in the object in certain cases, so its getting returned as undefined. If I was to try and render the header using the #=count# syntax it would fail, with the same error I was getting in the original post. 
0
Kelso
Top achievements
Rank 1
answered on 12 Sep 2014, 02:13 PM
Sorry, just another point to maybe help pinpoint some of the issue, It happens when the group field contains a string that has a similar value, eg: "Inspire Comm", "Inspire PS"
0
Kelso
Top achievements
Rank 1
answered on 10 Oct 2014, 01:43 PM
Has this issue been fixed? I am still getting an issue with count not being defined. I am using 2014.2.903
0
Vladimir Iliev
Telerik team
answered on 13 Oct 2014, 07:33 AM
Hello Kelso,

The issue is still not fixed on our side, however it's added with high priority to our queue. Currently however I can't be specific exactly when the fix will released (most probably to the end of the month) - that why I would suggest to regularly check our RoadMap for updates on the matter.

Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Kelso
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Kelso
Top achievements
Rank 1
Share this question
or