您需要向lightbox添加一个自定义Duration控件,以指定任务的开始日期和天数。
如何在jQuery的基础上添加一个自定义的Duration控件:

在页面中包含jQuery库的源文件:
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script><script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script><link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
描述控制逻辑:
(function () { function startDatepicker(node){ return $(node).find("input[name='start']"); } function durationInput(node){ return $(node).find("input[name='duration']"); } function endDateLabel(node){ return $(node).find("span.gantt-lb-datepicker-label"); } var formatter = gantt.ext.formatters.durationFormatter({ enter: "day", store: "day", format: "auto" }); gantt.form_blocks["datepicker_duration"] = { render: function (sns) { //sns - the section's configuration object return "<div class='gantt-lb-datepicker'>"+ "<label>Start:<input type='text' name='start'></label>"+ "<label>Duration: <input type='text' name='duration'></label>"+ "<span class='gantt-lb-datepicker-label'></span>" "</div>"; }, set_value: function (node, value, task, section) { //node - an html object related to the html defined above //value - a value defined by the map_to property //task - the task object //section- the section's configuration object startDatepicker(node).datepicker({ dateFormat: "yy-mm-dd", onSelect: function (dateStr) { var endValue = durationInput(node).datepicker('getDate'); var startValue = startDatepicker(node).datepicker('getDate'); if(startValue && endValue){ if(endValue.valueOf() <= startValue.valueOf()){ durationInput(node).datepicker("setDate", gantt.calculateEndDate({ start_date: startValue, duration: 1, task:task }) ); } } } }); startDatepicker(node).datepicker("setDate", task.start_date); durationInput(node).val(formatter.format(task.duration)); endDateLabel(node).text( "Ends: " + gantt.templates.task_date(task.end_date) ); }, get_value: function (node, task, section) { if(task.start_date && task.end_date) { var start = startDatepicker(node).datepicker('getDate'); var end = task.end_date; var duration = formatter.parse(durationInput(node).val()); if(duration && !isNaN(Number(duration))){ end = gantt.calculateEndDate({ start_date: start, duration: duration, task:task }); } task.start_date = start; task.duration = duration; task.end_date = end; } task.duration = gantt.calculateDuration(task); return { start_date: task.start_date, end_date: task.end_date, duration: task.duration } }, focus: function (node) { } }})();
将该控件作为类型为”datepicker_duration”的灯箱部分使用:
gantt.config.lightbox.sections = [ { name: "description", height: 70, map_to: "text", type: "textarea", focus: true }, { name: "time", height: 72, map_to: "auto", type: "datepicker_duration" }];
DHTMLX Gantt享有超十年声誉,支持跨浏览器和跨平台,性价比高,可满足项目管理控件应用的所有需求,是最完善的甘特图图表库。2022年终狂欢火热进行中,知名软控件产品享超低折扣,满额豪礼赠,复购双重大礼!了解更多内容,欢迎在线咨询或者私信我获取正版试用版及 价。
甘特图控件交流群:764148812 欢迎进群交流讨论
年终狂欢季,全场产品,限时特惠,立即了解详情!
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!