jQWidgets是一套基于jQuery的快速开发Web应用程序的UI库,提供了大量的可继承的UI部件和插件,其中之一是jqxScheduler控件。jqxScheduler是一个功能强大的基于可编辑日历的Web日历控件,提供了许多有用的日程管理和日历显示功能,例如:显示工作/空闲状态、日历导航、事件编辑器等。而cellDoubleClick事件则是jqxScheduler控件的一个重要事件之一,此事件会在用户在jqxScheduler控件上双击某个日期单元格时触发,本文将详细讲解如何使用“jQWidgets jqxScheduler cellDoubleClick事件”。
一、事件说明
jqxScheduler控件的cellDoubleClick事件具有以下属性:
-
event - {Object} - 事件对象。
-
appointment - {Object} - 对应日期单元格的预约对象。
-
$target - {jQuery Object} - 事件触发的jQuery对象。
二、事件绑定
使用jqxScheduler控件的cellDoubleClick事件时,必须将事件绑定到现有的jqxScheduler控件上。您可以使用以下代码为jqxScheduler控件绑定cellDoubleClick事件:
$('#scheduler').on('cellDoubleClick', function (event) {
// Handle the event here.
});
此代码将为ID为“scheduler”的具有jqxScheduler插件的元素添加cellDoubleClick事件回调。在事件回调函数中,您可以访问cellDoubleClick事件的属性。
三、示例说明
在以下示例中,我们将创建一个具有jqxScheduler控件的演示页面,并在该控件上显示某个时间段内的事件。并演示在当时双击日期单元格时会触发cellDoubleClick事件的情况。
示例1
以下示例演示了如何在jqxScheduler控件上显示包括事件和周/工作日视图,并处理cellDoubleClick事件。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>示例1:jqxScheduler控件演示</title>
<!-- 引入jQWidgets的CSS和JavaScript文件 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxdatetimeinput.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxscheduler.js"></script>
<style>
#scheduler {
margin: 10px;
width: 95%;
height: 500px;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
// Initialize the jqxScheduler control.
$('#scheduler').jqxScheduler({
width: '100%',
height: '100%',
theme: 'energyblue',
source: [],
appointmentDataFields: {
from: 'start',
to: 'end',
id: 'id',
description: 'description',
location: 'location',
subject: 'subject',
resourceId: 'calendar',
backgroundColor: 'backgroundColor',
borderColor: 'borderColor'
},
views: [
'dayView',
'weekView',
],
view: 'weekView',
showLegend: true,
resources: {
colorScheme: 'scheme04',
dataField: 'calendar',
source: new $.jqx.dataAdapter({
localData: [
{ id: '3', calendar: 'Red', borderColor: '#FF0000', backgroundColor: '#FFCCCC' },
{ id: '4', calendar: 'Blue', borderColor: '#0000FF', backgroundColor: '#CCCCFF' },
{ id: '5', calendar: 'Green', borderColor: '#008000', backgroundColor: '#CCFFCC' }
],
dataType: 'array'
})
}
});
// Bind to the cellDoubleClick event.
$('#scheduler').on('cellDoubleClick', function(event) {
var args = event.args;
var $target = $(args.$target);
var appointment = args.appointment;
alert("Double-clicked on cell " + $target.attr('id') + " with appointment id " + appointment.id);
});
// Load sample data.
var appointments = [
{
id: '1',
subject: "Meeting with team",
description: "Meet to discuss project plan.",
location: "Meeting Room 1",
calendar: '4',
backgroundColor: '#CCCCFF',
borderColor: '#0000FF',
start: new Date(2019, 1, 21, 9, 0, 0),
end: new Date(2019, 1, 21, 11, 0, 0)
},
{
id: '2',
subject: "Meeting with customer",
description: "Meet to discuss project details.",
location: "Meeting Room 2",
calendar: '3',
backgroundColor: '#FFCCCC',
borderColor: '#FF0000',
start: new Date(2019, 1, 27, 10, 0, 0),
end: new Date(2019, 1, 27, 12, 0, 0)
},
{
id: '3',
subject: "Demo",
description: "Present project demo.",
location: "Meeting Room 3",
calendar: '5',
backgroundColor: '#CCFFCC',
borderColor: '#008000',
start: new Date(2019, 1, 28, 10, 0, 0),
end: new Date(2019, 1, 28, 11, 0, 0)
}
];
$('#scheduler').jqxScheduler({
source: new $.jqx.dataAdapter({
dataFields: [
{ name: 'id', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'location', type: 'string' },
{ name: 'subject', type: 'string' },
{ name: 'calendar', type: 'string' },
{ name: 'backgroundColor', type: 'string' },
{ name: 'borderColor', type: 'string' },
{ name: 'start', type: 'date', format: 'yyyy-MM-dd HH:mm' },
{ name: 'end', type: 'date', format: 'yyyy-MM-dd HH:mm' }
],
localData: appointments
})
});
});
</script>
</head>
<body>
<h1>示例1:jqxScheduler控件演示</h1>
<div id="scheduler"></div>
</body>
</html>
示例2
以下示例演示如何在jqxScheduler控件上显示包括事件和月视图,并处理cellDoubleClick事件。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>示例2:jqxScheduler控件演示</title>
<!-- 引入jQWidgets的CSS和JavaScript文件 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/styles/jqx.base.css" type="text/css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxdatetimeinput.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxbuttons.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqwidgets/5.6.0/jqwidgets/jqxscheduler.js"></script>
<style>
#scheduler {
margin: 10px;
width: 95%;
height: 500px;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
// Initialize the jqxScheduler control.
$('#scheduler').jqxScheduler({
width: '100%',
height: '100%',
theme: 'energyblue',
source: [],
appointmentDataFields: {
from: 'start',
to: 'end',
id: 'id',
description: 'description',
location: 'location',
subject: 'subject',
resourceId: 'calendar',
backgroundColor: 'backgroundColor',
borderColor: 'borderColor'
},
views: [
'dayView',
'weekView',
'monthView'
],
view: 'monthView',
showLegend: true,
resources: {
colorScheme: 'scheme04',
dataField: 'calendar',
source: new $.jqx.dataAdapter({
localData: [
{ id: '3', calendar: 'Red', borderColor: '#FF0000', backgroundColor: '#FFCCCC' },
{ id: '4', calendar: 'Blue', borderColor: '#0000FF', backgroundColor: '#CCCCFF' },
{ id: '5', calendar: 'Green', borderColor: '#008000', backgroundColor: '#CCFFCC' }
],
dataType: 'array'
})
}
});
// Bind to the cellDoubleClick event.
$('#scheduler').on('cellDoubleClick', function(event) {
var args = event.args;
var $target = $(args.$target);
var appointment = args.appointment;
alert("Double-clicked on cell " + $target.attr('id') + " with appointment id " + appointment.id);
});
// Load sample data.
var appointments = [
{
id: '1',
subject: "Meeting with team",
description: "Meet to discuss project plan.",
location: "Meeting Room 1",
calendar: '4',
backgroundColor: '#CCCCFF',
borderColor: '#0000FF',
start: new Date(2019, 1, 21, 9, 0, 0),
end: new Date(2019, 1, 21, 11, 0, 0)
},
{
id: '2',
subject: "Meeting with customer",
description: "Meet to discuss project details.",
location: "Meeting Room 2",
calendar: '3',
backgroundColor: '#FFCCCC',
borderColor: '#FF0000',
start: new Date(2019, 1, 27, 10, 0, 0),
end: new Date(2019, 1, 27, 12, 0, 0)
},
{
id: '3',
subject: "Demo",
description: "Present project demo.",
location: "Meeting Room 3",
calendar: '5',
backgroundColor: '#CCFFCC',
borderColor: '#008000',
start: new Date(2019, 1, 28, 10, 0, 0),
end: new Date(2019, 1, 28, 11, 0, 0)
}
];
$('#scheduler').jqxScheduler({
source: new $.jqx.dataAdapter({
dataFields: [
{ name: 'id', type: 'string' },
{ name: 'description', type: 'string' },
{ name: 'location', type: 'string' },
{ name: 'subject', type: 'string' },
{ name: 'calendar', type: 'string' },
{ name: 'backgroundColor', type: 'string' },
{ name: 'borderColor', type: 'string' },
{ name: 'start', type: 'date', format: 'yyyy-MM-dd HH:mm' },
{ name: 'end', type: 'date', format: 'yyyy-MM-dd HH:mm' }
],
localData: appointments
})
});
});
</script>
</head>
<body>
<h1>示例2:jqxScheduler控件演示</h1>
<div id="scheduler"></div>
</body>
</html>
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:jQWidgets jqxScheduler cellDoubleClick事件 - Python技术站