search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Pass additional data to makeDraggable

Asked by Matt
9 years ago.

Hi there

Is there a way to pass additional event data when calling makeDraggable?

For example, our standard event may look something like:

ev = {id: 123, duration: 1800, text: "Hello", status: "unallocated"}

We use the 'status' to change the HTML rendered in onBeforeEventRender. However if we do this:

ev = {element: externalElement, id: 123, duration: 1800, text: "Hello", status: "unallocated"}
DayPilot.Scheduler.makeDraggable(ev);

When the event is rendered in onbeforeEventRender, the 'status' key is missing on the args.e?

Anyway to send this through?

Thanks
Matt

Answer posted by Dan Letecky [DayPilot]
8 years ago.

Build 1736 now copies all properties of the makeDraggable parameter (except of "duration" and "element") to the newly created DayPilot.Event.data property (which is accessible in onBeforeEventRender as args.e).

This means you can specify additional properties directly (such as barColor, backColor, etc.):

var item = {
    element: e,  // source element that will be removed from DOM on drop
    id: "1",
    text: "Event text",
    duration: 3600,  // 1 hour
    barColor: "red",
    barBackColor: "white"
};
DayPilot.Scheduler.makeDraggable(item);

You can also specify custom properties to be used in onBeforeEventRender. It is recommended to store custom properties in "tags" object (in order to prevent conflict with the standard properties in the future):

var item = {
    element: e,  // source element that will be removed from DOM on drop
    id: "1",
    text: "Event text",
    duration: 3600,  // 1 hour
    tags: { 
      color: "red",
      status: "unallocated"
    }
};
DayPilot.Scheduler.makeDraggable(item);


dp.onBeforeEventRender = function(args) {
  if (args.e.tags && args.e.tags.status === "unallocated") {
    args.html = "unallocated";
  }
};

You can download the latest build in the sandbox:
http://javascript.daypilot.org/sandbox/scheduler/external.html

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.