Scheduler throwing sortForGrouping error when using Resource Grouping

3 posts, 1 answers
  1. Jayaram Krishnan
    Jayaram Krishnan avatar
    10 posts
    Member since:
    Apr 2017

    Posted 05 Nov Link to this post

    Hi,

     

    My scheduler is working until the moment i add resource grouping, it will throw this error:

    kendo.all.js:5317 Uncaught TypeError: Cannot read property 'length' of undefined
        at r.sort (kendo.all.js:5317)
        at r._sortForGrouping (kendo.all.js:5403)
        at r.groupBy (kendo.all.js:5376)
        at r.group (kendo.all.js:5354)
        at Function.r.process (kendo.all.js:5525)
        at init._queryProcess (kendo.all.js:6941)
        at init._process (kendo.all.js:6931)
        at init.success (kendo.all.js:6683)
        at success (kendo.all.js:6610)
        at Object.ye.extend.read.n.success (kendo.all.js:5599)

     

    The line that causes the error is:

    group: { resources: ["Colleges"]},

     

    My code and a sample of the datasource json response are below:

    var tz = "Asia/Dubai";
        
        $(document).ready(function () {
            $("#scheduler").kendoScheduler({
                date: new Date(),
                selectable: true,
                editable: {
                    template: $("#editor").html(),
                    editRecurringMode: "dialog"
                },
                edit: function (e) {
                    console.log(e.event);
                    e.preventDefault();
                    if(e.event.id!=0)
                    {
                        url = '@Url.Action("Details", new { id = "id" })';
                        url = url.replace('id', e.event.id);
                    }
                    else
                    {
                        var selectedStartDate = ("0"+(e.event.start.getDate())).slice(-2)  + "-" + ("0"+(e.event.start.getMonth()+1)).slice(-2) + "-" + e.event.start.getFullYear() + " " + ("0" + e.event.start.getHours()).slice(-2) + ":" + ("0" + e.event.start.getMinutes()).slice(-2);
                        var selectedEndDate = ("0"+(e.event.end.getDate())).slice(-2)  + "-" + ("0"+(e.event.end.getMonth()+1)).slice(-2) + "-" + e.event.end.getFullYear() + " " + ("0" + e.event.end.getHours()).slice(-2) + ":" + ("0" + e.event.end.getMinutes()).slice(-2);
                        url= '@Url.Action("Create")?startDate=' + selectedStartDate+'&endDate=' + selectedEndDate;
                        
                    }
                    window.location = url;
                },
                change: function (e) {
                    $("#viewBTN").prop('disabled', (e.events==null || e.events.length!=1));
                    canCancel = (e.events!=null && e.events.length==1);
                    if (canCancel == true)
                        canCancel = canCancel && e.events[0].StatusID == @CarBookingStatusTypes.Approved.ToInt();
                    if (canCancel == true)
                        canCancel = canCancel && e.events[0].FromDate > new Date();
                    $("#deleteBTN").prop('disabled', !canCancel);
                    $("#editBTN").prop('disabled', (e.events==null || e.events.length!=1));
     
                    var canAttendTo = (e.events!=null && e.events.length==1);
                    
                    if (canAttendTo == true)
                        canAttendTo = canAttendTo && e.events[0].StatusID == @CarBookingStatusTypes.Pending.ToInt();
                  
                    $("#attendToBTN").prop('disabled', !canAttendTo);
                    
                }
                 
               , views: [
                {
                    type: "day", showWorkHours: true, showWorkHours: true, workWeekStart: 7,
                    workWeekEnd: 4
                },
                {
                    type: "week", selected: true, showWorkHours: true, workWeekStart: 7,
                    workWeekEnd: 4
                },
                "month"
               ],
                 
                timezone: tz,  dataSource:{
                    batch: false,
                    serverFiltering: true,
                    
                    "type": "aspnetmvc-ajax",
                    transport: {
                        read: {
                            url: "/CarBookings/GetAllBookings"
                            
                            , dataType: "json"
                            , data: function (e) {
                                var scheduler = $("#scheduler").data("kendoScheduler");
     
                                var result = {
                                    FromDate: scheduler.view().startDate().toISOString(),
                                    ToDate: new Date(scheduler.view().endDate().getTime() + ((23 * 60 * 60 * 1000) + (59 * 60 * 1000) + (59 * 1000)+ 999)).toISOString()
                                    ,skip: scheduler.dataSource.skip(),
                                    take: scheduler.dataSource.take(),
                                    sort:scheduler.dataSource.sort(),
                                    page:scheduler.dataSource.page()
                                }
     
                                return result;
                            }
                        },
                        destroy: {
                            url: "/OffenderSchedules/Delete",
                            dataType: "json"
                        }
                        , parameterMap: function (data, operation) {
                            console.log("operation:" + operation);
                            if (operation === "update" || operation === "create") {
                               
                                data.Start = kendo.toString(kendo.parseDate(data.Start), "G");
                                
                                data.End = data.Start;
                                
                                return JSON.stringify({ postedItem: data });
                               
                            } else if (operation === "read") {
     
                                
                                var scheduler = $("#scheduler").data("kendoScheduler");
                                var endDate = new Date(scheduler.view().endDate().getTime() + ((23 * 60 * 60 * 1000) + (59 * 60 * 1000) + (59 * 1000)));
     
                                if (data.filter === undefined) {
                                    
                                    data = $.extend({
                                        filter: {
                                            logic: "and",
                                            filters: [
                                                      { operator: "gte", field: "FromDate", value: kendo.toString(kendo.parseDate(scheduler.view().startDate()), "G") },
                                                      { operator: "lte", field: "ToDate", value: kendo.toString(kendo.parseDate(endDate), "G") }
                                            ]
                                        }
                                    }, data);
                                }
                                else if (data.filter.filters === undefined) {
                                    
                                    data = $.extend({
     
                                        filters: [
                                                  { operator: "gte", field: "FromDate", value: kendo.toString(kendo.parseDate(scheduler.view().startDate()), "G") },
                                                  { operator: "lte", field: "ToDate", value: kendo.toString(kendo.parseDate(endDate), "G") }
                                        ]
                                    }
                                    , data.filter);
                                }
                                else {
                                     
                                    data.filter.filters.push({
                                        logic: "and", filters: [
                                                        { operator: "gte", field: "FromDate", value: kendo.toString(kendo.parseDate(scheduler.view().startDate()), "G") },
                                                  { operator: "lte", field: "ToDate", value: kendo.toString(kendo.parseDate(endDate), "G") }
                                        ]
                                    });
     
                                }
                            }
                           
                            return data;
                            
                        }
                         
                    }
                    ,
                    group: { resources: ["Colleges"]},
                    resources: [
                        {
                            field: "collegeID",
                           
                            name: "Colleges",
                            
                             dataSource:[
                                { text: "Central Services", value: 5, color: "#6eb3fa" }
                               , { text: "College 2", value: 4, color: "#f58a8a" }
                            ],
                            title: "College"
                        }
                    ],
                    schema: {
                        parse: function (response) {
                           
                            for (var i = 0; i < response.Data.length; i++) {
                                if (response.Data[i].VehicleDisplayName == null)
                                    response.Data[i]['Title'] = "To:" + response.Data[i].ToLocationText + ', Passengers:' +
                                        response.Data[i].CarBookingPassengersList;
                                else
                                    response.Data[i]['Title'] = "#:" + response.Data[i].VehicleNumber + "," + response.Data[i].VehicleDisplayName + ",To:" + response.Data[i].ToLocationText + ',Passengers:' +
                                        response.Data[i].CarBookingPassengersList;
     
                            }
                             
                            return response;
                        },
     
                        data: "Data",
     
                        model: {
                            id: "ID",
                            fields: {
     
                                
                                ID: {
                                    from: "ID",
                                    type: "number"
                                },
                                collegeID: { from: "CollegeID",type: "number", nullable: true },
                                title: { from: "Title", validation: { required: true } },
                                start: { type: "date", from: "FromDate" },
                                end: { type: "date", from: "ToDate" },
                                
                                description: { from: "VehicleDisplayName" },
                                recurrenceId: { from: "RecurrenceID" },
                                recurrenceRule: { from: "RecurrenceRule" },
                                recurrenceException: { from: "RecurrenceException" },
                                isAllDay: { from: "IsAllDay" },
                                startTimezone: { type: "string", defaultValue: tz },
                                endTimezone: { type: "string", defaultValue: tz }                         
                            }
                        }
                    },            
                    sort:{ field:"FromDate",dir:"asc"}
                    ,change: function(e)
                    {
                         
                    }
                }
            });
        });

     

    datasource response sample:

    {"Data":[{"CreatedByDriver":null,"ID":11,"ApprovalStatusID":null,"StatusID":526,"VehicleID":null,"VehicleNumber":null,"FromDate":"\/Date(1509393600000)\/","ToDate":"\/Date(1509485400000)\/","CreatedByID":"a5cc4472-055a-41f1-96ac-ae024f20869f","DateCreated":"\/Date(1509432711343)\/","LastUpdatedByID":null,"DateLastUpdated":null,"CreatedByName":"User1 ","LastUpdatedByName":null,"StatusName":"Pending","CollegeID":5,"CollegeName":"College 1","FromLocationID":5,"ToLocationID":4,"FromLocationName":"Central Services","FromLocationText":"Central Services","ToLocationName":"College 2","ToLocationText":"College 1","RecurrenceID":null,"RecurrenceRule":null,"RecurrenceException":null,"IsAllDay":false,"CarBookingComments":"I would need to book a car ","ApprovalComments":null,"Vehicle":null,"VehicleDisplayName":","CarBookingPassengersList":"","DriverID":null,"DriverName":null,"DriverAspNetUserName":null,"IsEmergency":true,"PassengerIDs":null,"CarBookingPassengerNames":[],"CreatedByCollegeName":null}]

     

    Thanks

    Madani

     

     

     

     

  2. Answer
    Tyler
    Tyler avatar
    38 posts
    Member since:
    Feb 2017

    Posted 06 Nov in reply to Jayaram Krishnan Link to this post

    Your resources and group seem to be inside your dataSource field in the scheduler initialization. Take them out of the dataSource and just have them as scheduler fields.

    The dataSource does have a group option, but it takes a field name, not a resource collection. The scheduler group does take a resource collection, however.

    Here is a dojo with your code (much of it is removed so it will run in a dojo) with the correct grouping I believe you are after. The resources and group options were taken out of the dataSource and put under the scheduler instead.

  3. Jayaram Krishnan
    Jayaram Krishnan avatar
    10 posts
    Member since:
    Apr 2017

    Posted 07 Nov in reply to Tyler Link to this post

    Thanks Tyler, I do not know how I missed that when writing the code !!!.
Back to Top