Click a day in someone's row, then add a shift:
Drag a shift to another person or day, or stretch it - a shift lasts 4 to 10 hours.
PersonShiftsHoursThis week
Team

jQuery Scheduler: Shift Planner

A week's staff rota on jqxScheduler's timeline week view. Each person is a resource; shifts are added from templates or dragged from person to person; minDuration and maxDuration keep a shift between 4 and 10 hours and allowOverlap: false stops anyone working two shifts at once. The hours per person add up as the rota changes, and every change can be undone.

A live JavaScript/jQuery example of jqxScheduler, the jQWidgets Scheduler component, with its complete source code below. It is one of 45 jqxScheduler demos for jQuery.

jqxScheduler API used in this demo

Source code

To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxScheduler shows the setup step by step.

The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxscrollbar.js, jqxdata.js, jqxdate.js, jqxscheduler.js, jqxscheduler.api.js, jqxdatetimeinput.js, jqxmenu.js, jqxcalendar.js, jqxtooltip.js, jqxwindow.js, jqxcheckbox.js, jqxlistbox.js, jqxdropdownlist.js, jqxnumberinput.js, jqxradiobutton.js, jqxinput.js.

It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).

script.js

$(document).ready(function () {
    // The week of 16 November 2026 for a team of six. People are the resources of a timeline week
    // view; a shift is an appointment. The rota's rules are settings, so dragging, resizing, the
    // templates below and the edit dialog all keep to them: a shift lasts 4 to 10 hours, and nobody
    // works two shifts at once.
    var people = ['Alex Morgan', 'Bea Novak', 'Chris Diaz', 'Dana Lee', 'Eli Brooks', 'Farah Aziz'];
    var shiftTypes = {
        M: { name: 'Morning', from: 6, to: 14, color: '#d97706' },
        D: { name: 'Day', from: 9, to: 17, color: '#2563eb' },
        E: { name: 'Evening', from: 14, to: 22, color: '#7c3aed' }
    };
    // Monday to Sunday, one letter a day
    var plans = ['MMMMM--', 'DD-DDD-', 'EEE--EE', '-MDDE--', 'E-EEEED', 'DDDD---'];
    var shifts = [];
    $.each(plans, function (p, plan) {
        for (var d = 0; d < 7; d++) {
            var type = shiftTypes[plan.charAt(d)];
            if (type) {
                shifts.push({ id: 's' + p + d, subject: type.name, person: people[p], color: type.color,
                    start: new Date(2026, 10, 16 + d, type.from), end: new Date(2026, 10, 16 + d, type.to) });
            }
        }
    });

    var source = {
        dataType: 'array',
        dataFields: [
            { name: 'id', type: 'string' },
            { name: 'subject', type: 'string' },
            { name: 'person', type: 'string' },
            { name: 'color', type: 'string' },
            { name: 'start', type: 'date' },
            { name: 'end', type: 'date' }
        ],
        id: 'id',
        localData: shifts
    };
    var peopleSource = { dataType: 'array', dataFields: [{ name: 'person', type: 'string' }], localData: $.map(people, function (p) { return { person: p }; }) };

    $('#scheduler').jqxScheduler({
        date: new $.jqx.date(2026, 11, 16),
        width: '100%',
        height: 460,
        rowsHeight: 40,
        source: new $.jqx.dataAdapter(source),
        view: 'timelineWeekView',
        // the week starts on Monday
        localization: { firstDay: 1 },
        resources: {
            colorScheme: 'scheme23',
            dataField: 'person',
            orientation: 'vertical',
            source: new $.jqx.dataAdapter(peopleSource)
        },
        appointmentDataFields: { from: 'start', to: 'end', id: 'id', subject: 'subject', resourceId: 'person', style: 'color' },
        views: [
            { type: 'timelineWeekView', timeSlotWidth: 26, workTime: { fromDayOfWeek: 0, toDayOfWeek: 6, fromHour: 6, toHour: 22 }, timeRuler: { scale: 'hour', scaleStartHour: 6, scaleEndHour: 21, formatString: 'HH' } }
        ],
        // the rota's rules
        minDuration: 4 * 60,
        maxDuration: 10 * 60,
        allowOverlap: false
    });

    var pad = function (n) { return (n < 10 ? '0' : '') + n; };
    var dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
    var status = function (ok, text) {
        $('#status').removeClass('ok no').addClass(ok ? 'ok' : 'no').text(text);
    };

    // ---- add a shift: click a person's day, then a template ----
    var target = null;
    $('#scheduler').on('cellClick', function () {
        var selection = $('#scheduler').jqxScheduler('getSelection');
        if (selection && selection.resourceId) {
            var day = selection.from.toDate();
            target = { person: selection.resourceId, day: new Date(day.getFullYear(), day.getMonth(), day.getDate()) };
            $('#target').text('Add to ' + target.person + ', ' + dayNames[target.day.getDay()] + ' ' + target.day.getDate() + ' Nov:');
        }
    });
    $.each(shiftTypes, function (code, type) {
        $('<input type="button" />').val(type.name + ' ' + pad(type.from) + '-' + pad(type.to)).appendTo('#templates').jqxButton({ height: 30 })
            .on('click', function () {
                if (!target) {
                    status(false, 'Click a day in someone\'s row first.');
                    return;
                }
                var d = target.day;
                var added = $('#scheduler').jqxScheduler('addAppointment', {
                    subject: type.name, person: target.person, color: type.color,
                    start: new Date(d.getFullYear(), d.getMonth(), d.getDate(), type.from), end: new Date(d.getFullYear(), d.getMonth(), d.getDate(), type.to)
                });
                if (added) {
                    status(true, type.name + ' shift added for ' + target.person + ' on ' + dayNames[d.getDay()] + ' ' + d.getDate() + ' Nov.');
                }
            });
    });

    // ---- undo / redo ----
    $('#undo').jqxButton({ height: 30, disabled: true }).on('click', function () { $('#scheduler').jqxScheduler('undo'); });
    $('#redo').jqxButton({ height: 30, disabled: true }).on('click', function () { $('#scheduler').jqxScheduler('redo'); });
    $('#scheduler').on('undoRedoChange', function (event) {
        $('#undo').jqxButton({ disabled: !event.args.canUndo });
        $('#redo').jqxButton({ disabled: !event.args.canRedo });
    });

    // what the rules turned down, and why
    $('#scheduler').on('appointmentAdding appointmentChanging', function (event) {
        if (event.args.cancel && event.args.reason) {
            status(false, event.args.reason.message + '.');
        }
    });
    $('#scheduler').on('appointmentChange', function (event) {
        var a = event.args.appointment, from = a.from.toDate();
        status(true, (event.args.action ? event.args.action + ': ' : '') + a.subject + ' shift is now ' + a.resourceId + ', ' + dayNames[from.getDay()] + ' ' +
            pad(from.getHours()) + ':' + pad(from.getMinutes()) + '-' + pad(a.to.toDate().getHours()) + ':' + pad(a.to.toDate().getMinutes()) + '.');
    });

    // ---- hours per person ----
    var renderHours = function () {
        var hours = {}, count = {}, total = 0;
        $.each(people, function () { hours[this] = 0; count[this] = 0; });
        $.each($('#scheduler').jqxScheduler('getAppointments'), function () {
            if (hours[this.resourceId] === undefined) return;
            var h = (this.to.toDate() - this.from.toDate()) / 3600000;
            hours[this.resourceId] += h;
            count[this.resourceId]++;
            total += h;
        });
        $('#hours tbody').empty().append($.map(people, function (person) {
            var h = hours[person], over = h > 40;
            return $('<tr></tr>').toggleClass('over', over)
                .append($('<td></td>').text(person))
                .append($('<td class="num"></td>').text(count[person]))
                .append($('<td class="num"></td>').text(h + ' h'))
                .append($('<td></td>').append($('<div class="bar"></div>').css('width', Math.min(100, h / 50 * 100) + '%')))
                .append($('<td class="note"></td>').text(over ? 'over 40 h' : ''));
        }));
        $('#total').text(total + ' h');
    };
    $('#scheduler').on('appointmentAdd appointmentChange appointmentDelete', renderHours);
    renderHours();
});

body.html

<div id="content" class="demo">
    
    <div class="demo-bar">
        <span id="target" class="demo-target">Click a day in someone's row, then add a shift:</span>
        <span id="templates" class="demo-templates"></span>
        <span class="sep"></span>
        <input type="button" id="undo" value="Undo">
        <input type="button" id="redo" value="Redo">
    </div>
    <div id="scheduler"></div>
    <div id="status" class="demo-status" role="status" aria-live="polite">Drag a shift to another person or day, or stretch it - a shift lasts 4 to 10 hours.</div>
    <table id="hours" class="demo-hours">
        <thead><tr><th>Person</th><th>Shifts</th><th>Hours</th><th style="width: 40%">This week</th><th></th></tr></thead>
        <tbody></tbody>
        <tfoot><tr><td>Team</td><td></td><td id="total" class="num"></td><td></td><td></td></tr></tfoot>
    </table>
</div>

Learn more

More jQuery Scheduler demos