Skip to content

Data Management

Programmatically add, update, and remove timeline entries.

<html>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@calendarjs/ce/dist/style.min.css" />
<script src="https://cdn.jsdelivr.net/npm/lemonadejs/dist/lemonade.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@calendarjs/ce/dist/index.min.js"></script>

<button onclick="addEntry()">Add</button>
<button onclick="updateFirst()">Update</button>
<button onclick="removeLast()">Remove</button>
<div id="root"></div>

<script>
const { Timeline } = calendarjs;

const timeline = Timeline(document.getElementById('root'), {
    data: [
        { title: 'Project Started', date: '2025-01-01', borderColor: '#3498db' },
        { title: 'Time allocation meeting', date: '2025-01-02' }
    ],
    align: 'left'
});

function addEntry() {
    timeline.data.push({
        title: 'New Entry',
        date: '2025-02-01',
        borderColor: '#e74c3c'
    });
    timeline.refresh();
}

function updateFirst() {
    if (timeline.data.length > 0) {
        timeline.data[0].title = 'Updated Entry';
        timeline.data[0].borderColor = '#2ecc71';
        timeline.refresh();
    }
}

function removeLast() {
    if (timeline.data.length > 0) {
        timeline.data.pop();
        timeline.refresh();
    }
}
</script>
</html>