For some reason I cant get the events to load from my PHP backend. I've posted the code below, it seems everything is exactly the same as the examples, i just cant figure it out. I've messed with dates and having it create the events through a loop and none of it it showing, not sure what I'm missing. Any help would be appreciated. The data does return the information in properly formatted JSON like it should.
//JS Code
var dp = new DayPilot.Scheduler('schedule');
dp.cellDuration = 15;
dp.cellWidth = 15;
dp.days = '14';
dp.heightSpec = "Fixed";
dp.height = 650;
// dp.autoScroll = 'Always';
dp.resources = drivers;
dp.timeHeaders = [
{groupBy: 'Week'},
{groupBy: 'Day'},
{groupBy: 'Hour'}
];
dp.scale = "CellDuration";
dp.eventDoubleClickHandling = 'Enabled';
dp.onEventDoubleClicked = function (args) {
getEdit(args.e.id());
};
dp.contextMenu = new DayPilot.Menu({
items: [
{
text: "Edit", onclick: function () {
getEdit(this.source.id());
}
},
{
text: "Delete", onclick: function () {
dp.events.remove(this.source)
}
}
]
});
dp.dynamicLoading = true;
dp.onScroll = function (args) {
args.async = true;
var start = args.viewport.start;
var end = args.viewport.end;
$.post('/schedule/scroll', {
start: start.toString(),
end: end.toString()
},
function (data) {
args.events = JSON.parse(data);
args.loaded();
})
};
dp.onEventDelete = function (args) {
$.post('/schedule/delete', {
event_id: args.e.id()
}, function (data) {
}
)
};
dp.onEventMoved = function(args){
if (external){
$.post('/schedule/create', {
event_id : args.e.id(),
start : args.newStart.toString(),
end: args.newEnd.toString(),
text: args.e.text(),
resource : args.e.resource()
})
}else{
postUpdate(args);
}
};
dp.onEventResized = function (args) {
postUpdate(args)
};
function postUpdate(args){
$.post('/schedule/update', {
event_id : args.e.id(),
start : args.newStart.toString(),
end: args.newEnd.toString(),
text: args.e.text(),
resource: args.e.resource()
})
}
dp.init();
//PHP Code
public function postScroll(Request $request) {
$temps = TempSchedule::where('end', '>', $request->start)->where('start', '<', $request->end)->get();
$events = array();
foreach ($temps as $temp){
$e = new \stdClass();
$e->id = $temp->event_id;
$start = new \DateTime($temp->start);
$end = new \DateTime($temp->end);
$e->start = $start->format('c');
$e->end = $end->format('c');
$e->text = $temp->text;
$e->resource = $temp->resource;
$events[] = $e;
}
header('Content-Type: application/json');
echo json_encode($events);
}