Skip to main content
Version: 2.0.x

Calendar

Calendar is a view component for displaying and managing time-related data, based on Ant Design Calendar to implement schedule management, event management, and time planning functionality. It handles data source binding, schedule creation and editing, and interactive event processing, supporting drag operations, custom rendering, and multiple view modes.

The Calendar element has a hierarchical structure of Meta (components.Meta) → Type (components.Calendar) → Instance. Developers can quickly create Calendar instance elements through JitAI's visual development tools.

Of course, developers can also create their own Type elements or modify the official components.CalendarType element provided by JitAI in their own App to implement their own encapsulation.

Quick Start​

Basic Configuration Example​

Basic Calendar Configuration
{
"name": "calendar1",
"title": "Project Calendar",
"fullName": "components.Calendar",
"config": {
"requireElements": [
{
"title": "Project Data Model",
"type": "models.Meta",
"name": "models.ProjectModel",
"filter": "",
"orderBy": ""
}
],
"startTime": ["startDate"],
"endTime": ["endDate"],
"title": ["projectName"],
"scheduleType": ["status"],
"createSchedule": true,
"dragSchedule": true,
"defaultRender": true
}
}

Configuration Properties​

Property NameTypeDefault ValueDescriptionExample
requireElementsArray[]Associated data model configurationSee example above
startTimeArray[]Start time field mapping["startDate"]
endTimeArray[]End time field mapping["endDate"]
titleArray[]Title field mapping["projectName"]
scheduleTypeArray[]Schedule type field mapping["status"]
toolbarBtnArray[]Toolbar button configuration[]
columnBtnArray[]Column button configuration[]
createScheduleBooleantrueWhether to allow schedule creationtrue
dragScheduleBooleantrueWhether to allow schedule draggingtrue
defaultRenderBooleantrueWhether to use default renderingtrue

Variables​

activeRow​

Currently selected row data, containing schedule information that the user clicked or operated on.

activeRow Usage Example
// Get current selected row data
const currentRow = calendar1.activeRow;
console.log(currentRow.getValue());

// Listen for row data changes
calendar1.activeRow.subscribeEvent('change', (data) => {
console.log('Selected row data changed:', data);
});

Methods​

call​

Refresh calendar data, reload from data source and update display.

Usage Example​

Refresh Calendar Data
// Refresh calendar
await calendar1.call();

// Use in event handling
async function handleDataUpdate() {
await calendar1.call();
console.log('Calendar data refreshed');
}

publishEvent​

Send component event for inter-component communication.

Parameter Details​

Parameter NameTypeRequiredDescriptionExample
nameStringYesEvent name"clickRow"
exObjectNoAdditional data{customData: "value"}

Return Value​

Promise<void> - Async operation completion

Usage Example​

Send Component Event
// Send custom event
await calendar1.publishEvent('customEvent', {
message: 'Custom data',
timestamp: new Date()
});

subscribeEvent​

Subscribe to component event, listen for specific event triggers.

Parameter Details​

Parameter NameTypeRequiredDescriptionExample
nameStringYesEvent name"clickRow"
evtCbFunctionYesCallback function(data) => {...}
unSubscribeExistBooleanNoWhether to cancel existing subscriptiontrue

Return Value​

String - Event handler ID

Usage Example​

Subscribe to Component Event
// Subscribe to row click event
const handlerId = calendar1.subscribeEvent('clickRow', (data) => {
console.log('User clicked row:', data);
});

// Subscribe to schedule creation event
calendar1.subscribeEvent('afterCreateSchedule', async (data) => {
console.log('New schedule created:', data);
// Execute follow-up processing logic
});

unSubscribeEvent​

Cancel event subscription.

Parameter Details​

Parameter NameTypeRequiredDescriptionExample
idStringYesEvent handler ID"handler123"

Usage Example​

Cancel Event Subscription
// Cancel specific event subscription
calendar1.unSubscribeEvent(handlerId);

setConfig​

Set component configuration, dynamically update component behavior.

Parameter Details​

Parameter NameTypeRequiredDescriptionExample
nextObjectYesNew configuration object{createSchedule: false}
cleanBooleanNoWhether to completely replace configurationfalse

Usage Example​

Dynamic Component Configuration
// Disable schedule creation functionality
calendar1.setConfig({
createSchedule: false,
dragSchedule: false
});

// Update data source configuration
calendar1.setConfig({
requireElements: [{
title: "New Data Model",
type: "models.Meta",
name: "models.NewModel"
}]
});

destroy​

Destroy component instance, clean up resources and event listeners.

Usage Example​

Destroy Component
// Component destruction
calendar1.destroy();

runCode​

Execute custom code snippet, run in page context.

Parameter Details​

Parameter NameTypeRequiredDescriptionExample
codeStringYesCode string to execute"self.activeRow.getValue()"

Return Value​

Any - Code execution result

Usage Example​

Execute Custom Code
// Execute code to get data
const result = calendar1.runCode('self.activeRow.getValue()');
console.log(result);

getPermConfig​

Get current component's permission configuration.

Return Value​

Record<string, any> | undefined - Permission configuration object

Usage Example​

Get Permission Configuration
// Get component permission configuration
const permConfig = calendar1.getPermConfig();
if (permConfig) {
console.log('Component permissions:', permConfig);
}

Attributes​

Basic Attributes​

Attribute NameTypeDescriptionExample Value
nameStringComponent name, used to identify component instance"calendar1"
titleStringComponent title, name displayed on interface"Project Calendar"
typeStringComponent type identifier"components.Calendar"
fullNameStringComponent's complete name identifier"components.Calendar"
showTitleBooleanWhether to display component titletrue
compTypeEnumComponent type enum valueComponent type enum value
Access Basic Attributes Example
// Get component basic information
console.log('Component name: ' + calendar1.name + ', title: ' + calendar1.title);
console.log('Type: ' + calendar1.type + ', show title: ' + calendar1.showTitle);

config​

Component configuration object, containing all configuration parameters.

Access Component Configuration
const config = calendar1.config;
console.log(config.createSchedule); // true
console.log(config.startTime); // ["startDate"]

// Dynamic configuration check
if (config.dragSchedule) {
console.log('Drag functionality supported');
}

app​

Associated application instance, providing application-level functionality.

Use Application Instance
const app = calendar1.app;
// Get application element
const userModel = await app.getElement('models.UserModel');

page​

Associated page instance, providing page-level functionality.

Use Page Instance
const page = calendar1.page;
// Access other components on the page
const otherComponent = page.getComponent('otherComponentName');

Events​

clickRow​

Row click event, triggered when user clicks on a row in the calendar.

Event Data: activeRow - Currently clicked row data

Handle Row Click Event
calendar1.subscribeEvent('clickRow', (data) => {
console.log('Clicked row data:', data.activeRow);
// Handle row click logic
});

afterCreateSchedule​

After creating schedule event, triggered when user creates a new schedule.

Event Data: activeRow - Newly created schedule data

Handle Schedule Creation Event
calendar1.subscribeEvent('afterCreateSchedule', (data) => {
console.log('New schedule created:', data.activeRow);
// Send notification or update related data
});

afterDragSchedule​

After dragging schedule event, triggered when user drags and moves a schedule.

Event Data: activeRow - Schedule data after dragging

Handle Schedule Drag Event
calendar1.subscribeEvent('afterDragSchedule', (data) => {
console.log('Schedule after dragging:', data.activeRow);
// Save new time arrangement
});