翻譯|使用教程|編輯:董玉霞|2022-04-15 15:24:41.060|閱讀 296 次
概述:在DhtmlxGantt中自定義第三方 Duration 控件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
此功能僅在 Gantt PRO 版本中可用。
在DhtmlxGantt中自定義第三方 Duration 控件。
需要將自定義 Duration 控件添加到燈箱,以指定任務的開始日期和天數。
考慮如何在 jQuery 的基礎上添加自定義的 Duration 控件:
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="http://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> <link rel="stylesheet" type="text/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) { } } })();
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" } ];
更多關于DhtmlxGantt教程的內容可進入官網查看。
DhtmlxGantt是針對您的解決方案的交互式JavaScript / HTML5甘特圖。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn