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

Get Resource Value from Scheduler on Drop

1 Answer 76 Views
Drag and Drop
This is a migrated thread and some comments may be shown as answers.
MiDAS
Top achievements
Rank 1
MiDAS asked on 21 Nov 2019, 03:47 PM

Hi,

Following on from a previous post

I now have a grid view as the source for my drag items and dropping onto a scheduler and this works great when the scheduler is configured to show one resource. If the scheduler has a resource group I would like to not only pick the timeslot where the item was dropped but also the resource too.

My scheduler Resources are defined as:

var resourcesParam = '?d=' + String($kk_sDivisionFk) + '&t=' + String($kk_sTeamFk) + '&a=' + String($kk_sAssignee) + '&u=' + String($UserID);
        var schedulerResources = [
            {
                field: "assignee",
                name: "Assignee",
                dataTextField: "Text",
                dataValueField: "Value",
                dataSource: {
                    transport: {
                        read: {
                            url: '@Url.Content("~/Home/GetActiveMembers")' + resourcesParam,
                            dataType: 'json'
                        }
                    }
                },
                title: "Assignee"
            }
        ];

 

Based on the previous post... my create drag area is set as:

//Make the scheduler a drop area for drag and drop.
function createDropArea(scheduler) {
 
    var grid = $("#grid").data("kendoGrid"),
    gridRowOffset = grid.tbody.find("tr:first").offset();
 
    scheduler.view().content.kendoDropTargetArea({
        filter: ".k-scheduler-table td, .k-event",
        drop: function (e) {
 
            var offset = $(e.dropTarget).offset();
            var slot = scheduler.slotByPosition(offset.left, offset.top);
            var dataItem = grid.dataItem(grid.select());
 
            if (dataItem && slot) {
                var offsetMiliseconds = new Date().getTimezoneOffset() * 60000;
                var newEvent = {
                    eID: -1,
                    status: dataItem.status,
                    assignee: XXXXX, //This should be the dataValueField from schedulerResources above (it is an integer)
                    title: dataItem.title,
                    start: slot.startDate,
                    end: new Date(slot.startDate.getTime() + (dataItem.end - dataItem.start)),
                    requestType: dataItem.requestType,
                    lastUpdatedBy: currentUser,
                    isAllDay: dataItem.isAllDay,
                    startTimezone: dataItem.startTimezone,
                    endTimezone: dataItem.endTimezone
                };
 
                //grid.dataSource.remove(dataItem); //I don't need to remove item from grid.
                scheduler.dataSource.add(newEvent);
            }
 
        }
    });
}

 

Is there a way to get the assignee value? If it helps the scheduler has been restricted to timeline, timelineWeek and timelineMonth views.

Thanks.

 

 

 

1 Answer, 1 is accepted

Sort by
0
MiDAS
Top achievements
Rank 1
answered on 22 Nov 2019, 04:24 PM

After some more research I found the answer....

var slotResource = scheduler.resourcesBySlot(scheduler.slotByElement($(e.dropTarget)));

So my function is now:

//Make the scheduler a drop area for drag and drop.
function createDropArea(scheduler) {
  
    var grid = $("#grid").data("kendoGrid"),
    gridRowOffset = grid.tbody.find("tr:first").offset();
  
    scheduler.view().content.kendoDropTargetArea({
        filter: ".k-scheduler-table td, .k-event",
        drop: function (e) {
  
            var offset = $(e.dropTarget).offset();
            var slot = scheduler.slotByPosition(offset.left, offset.top);
            var slotResource = scheduler.resourcesBySlot(scheduler.slotByElement($e.dropTarget)));
            var dataItem = grid.dataItem(grid.select());
  
            if (dataItem && slot) {
                var offsetMiliseconds = new Date().getTimezoneOffset() * 60000;
                var newEvent = {
                    eID: -1,
                    status: dataItem.status,
                    assignee: slotResource.assignee,
                    title: dataItem.title,
                    start: slot.startDate,
                    end: new Date(slot.startDate.getTime() + (dataItem.end - dataItem.start)),
                    requestType: dataItem.requestType,
                    lastUpdatedBy: currentUser,
                    isAllDay: dataItem.isAllDay,
                    startTimezone: dataItem.startTimezone,
                    endTimezone: dataItem.endTimezone
                };
  
                //grid.dataSource.remove(dataItem); //I don't need to remove item from grid.
                scheduler.dataSource.add(newEvent);
            }
  
        }
    });
}

 

...

 

 

Tags
Drag and Drop
Asked by
MiDAS
Top achievements
Rank 1
Answers by
MiDAS
Top achievements
Rank 1
Share this question
or