Basically, i’m trying to create a simple booking system with a drag and drop jquery script.
I want that each event starts from almost half of each cell and also ends in the same way.
See the picture below.

I’ve implemented a draggable script but the problem is that, i don’t know why, the grid seems not working correctly and when the event gets moved it gets stuck on the beginning of the cell. Then i added a resizable to allow the user to enlarge each event but the resize doesn’t follow the grid.

I attach the entire Jquery Script.
var width = 200;
var correction_morning_evening = 30;
var events = [
{
title: 'Test 1',
vehicule: 1,
start: moment().add(4, 'days'),
end: moment().add(6, 'days'),
},
{
title: 'Test 2',
vehicule: 5,
start: moment().add(2, 'days'),
end: moment().add(4, 'days'),
},
{
title: 'Test 3',
vehicule: 5,
start: moment().add(7, 'days'),
end: moment().add(8, 'days'),
}
];
var now = moment().startOf('week');
var after = moment().add(11, 'days');
$('#table-left').find('tbody tr').each(function () {
$table.find('tbody').append($('<tr class="tr-event-timeline" id="tr-' + $(this).data('id') + '" style="display: flex"/>'));
});
var maxWidth = width * after.diff(now, 'days');
$table.css('width', maxWidth);
var week = null;
while (now.isBefore(after)) {
// render cell
var $tdBody = $('<td class="td-event" data-date="' + now.format('YYYY-MM-DD') + '" />');
//$tdBody.text(now.format('ddd'));
$tdBody.attr('width', width);
// Collapsed thread
var $tdHead = $('<td />');
$tdHead.append(now.format('ddd D') + '<br />' + now.format('MMM'));
$table.find('thead tr.tr-day').append($tdHead);
$table.find('tbody tr').append($tdBody);
if (week !== now.format('W')) {
var $tdHeadWeek = $('<td colspan="7" />');
$tdHeadWeek.html('WEEK ' + now.format('W'));
$table.find('thead tr.tr-week').append($tdHeadWeek);
}
week = now.format('W');
now.add(1, 'days');
}
// render events
$.each(events, function (i, event) {
var start = event.start;
var end = event.end;
// create div inside first $td
var $tr = $('#tr-' + event.vehicule);
var $tdFirst = $tr.find('td[data-date="' + start.format('YYYY-MM-DD') + '"]');
var eventWidth = end.diff(start, 'days');
var $eventDiv = $('<div class="label trs" />');
$eventDiv.html('<div class="event-item">' + event.title + '</div>');
$eventDiv.find('.event-item').css('width', "100%");
$eventDiv.css('width', (width * eventWidth) - (correction_morning_evening*2));
$eventDiv.css('left', correction_morning_evening);
$tdFirst.append($eventDiv);
// block every td
while (start.isBefore(end)) {
$tr.find('td[data-date="' + start.format('YYYY-MM-DD') + '"]').addClass('td-event-booked');
start.add(1, 'day');
}
$('.calendar-grid').height($('.calendar-grid').height() + 60);
});
// manage rendezvous
//$('.tr-event-timeline').selectable({
// filter: '.td-event-booked'
//});
$('.label').draggable({
snap: '.td-event:not(.td-event-booked)',
snapMode: "inner",
})
$('.label .event-item').resizable({
handles: 'e',
grid: [100,20],
stop: function (e, ui) {
$(this).parent().width(ui.size.width);
}
});
Do you have any ideas? How to fix this?