翻譯|使用教程|編輯:胡濤|2022-12-09 14:00:26.007|閱讀 242 次
概述:本文給大家講解DHTMLX Gantt的任務內容如何顯示,歡迎大家下載最新版試用體驗。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
DHTMLX Gantt是用于跨瀏覽器和跨平臺應用程序的功能齊全的Gantt圖表??蓾M足項目管理應用程序的大部分開發需求,具備完善的甘特圖圖表庫,功能強大,價格便宜,提供豐富而靈活的JavaScript API接口,與各種服務器端技術(PHP,ASP.NET,Java等)簡單集成,滿足多種定制開發需求。本文給大家講解DHTMLX Gantt的任務內容如何顯示,歡迎大家下載最新版試用體驗。
拖動允許用戶快速更改任務的開始(結束)日期及其持續時間。
默認情況下,拖放是啟用的,用戶可以在時間線中沿著它的行拖動任務。
要自定義拖放行為,請使用以下事件:
gantt.attachEvent("onBeforeTaskDrag", function(id, mode, e){ if(gantt.getGlobalTaskIndex(id)%2==0){ return false; //denies dragging if the global task index is odd } return true; //allows dragging if the global task index is even });
拒絕將任務拖出特定日期,請使用事件。
onTaskDrag 事件:
很快,一切都按以下順序發生:
假設您要禁止用戶將任務拖出“2020 年 3 月 31 日 - 2020 年 4 月 11 日”的時間間隔。
然后,您可以使用以下代碼:
拒絕將任務拖出間隔 - [31.03.2020, 11.04.2020]
var leftLimit = new Date(2020, 2 ,31), rightLimit = new Date(2020, 3 ,12); gantt.attachEvent("onTaskDrag", function(id, mode, task, original){ var modes = gantt.config.drag_mode; if(mode == modes.move || mode == modes.resize){ var diff = original.duration*(1000*60*60*24); if(+task.end_date > +rightLimit){ task.end_date = new Date(rightLimit); if(mode == modes.move) task.start_date = new Date(task.end_date - diff); } if(+task.start_date < +leftLimit){ task.start_date = new Date(leftLimit); if(mode == modes.move) task.end_date = new Date(+task.start_date + diff); } } });
要在用戶拖動其父項的任務時允許拖動子項,請使用事件(請參閱事件的更多信息):
gantt.attachEvent("onTaskDrag", function(id, mode, task, original){ var modes = gantt.config.drag_mode; if(mode == modes.move){ var diff = task.start_date - original.start_date; gantt.eachTask(function(child){ child.start_date = new Date(+child.start_date + diff); child.end_date = new Date(+child.end_date + diff); gantt.refreshTask(child.id, true); },id ); } }); //rounds positions of the child items to scale gantt.attachEvent("onAfterTaskDrag", function(id, mode, e){ var modes = gantt.config.drag_mode; if(mode == modes.move ){ var state = gantt.getState(); gantt.eachTask(function(child){ child.start_date = gantt.roundDate({ date:child.start_date, unit:state.scale_unit, step:state.scale_step }); child.end_date = gantt.calculateEndDate(child.start_date, child.duration, gantt.config.duration_unit); gantt.updateTask(child.id); },id ); } });
默認情況下,項目類型的任務不可拖動。您可以使用配置啟用項目拖放:
gantt.config.drag_project = true;
有幾種方法可以實現隨其相關任務一起移動的任務。”中閱讀所有這些內容。
可以通過min_duration設置指定最短任務持續時間。
該選項定義了在調整大小時可以設置的任務的最小大小,可用于防止用戶設置零持續時間。
該值以毫秒為單位設置:
// 1 day gantt.config.min_duration = 24*60*60*1000; //OR // 1 hour gantt.config.min_duration = 60*60*1000;
如果您在甘特圖中有一個大型數據集,您通常需要將任務拖到一個新的較遠位置,或者在相距很遠的任務之間設置鏈接。
在這種情況下,自動滾動功能會有很大幫助。它默認啟用,但您可以通過自動滾動配置選項管理此行為。
gantt.config.autoscroll = false; gantt.init("gantt_here"); 此外,您可以借助相應的屬性 - autoscroll_speed以毫秒為單位調整自動滾動的速度: gantt.config.autoscroll = true; gantt.config.autoscroll_speed = 50; gantt.init("gantt_here");
如果你想阻止某些任務被調整大小,你可以做兩件事:
通過 CSS 從 UI 中刪除任務的調整大小句柄。為此,您需要使用task_class模板向所需項目添加一個額外的 CSS 類,以便您可以通過選擇器找到它們:
gantt.templates.task_class = function(start, end, task){ if(task.no_resize) { // no_resize is a custom property used for the demonstration return "no_resize"; } return "";然后,您可以使用以下 CSS 隱藏調整大小的手柄:
.no_resize .gantt_task_drag{ display: none !important; } 使用onBeforeTaskDrag事件防止代碼拖放。從處理程序返回false將阻止調整大?。?gantt.attachEvent("onBeforeTaskDrag", function(id, mode, e){ if(mode === "resize" && gantt.getTask(id).no_resize){ return false; } return true; });
拖放的“調整大小”模式意味著用戶可以從開始日期或結束日期調整任務的大小。
如果您需要通過調整大小找出用戶正在修改的日期,您可以使用gantt.getState().drag_from_start標志:
gantt.attachEvent("onBeforeTaskDrag", function(id, mode, e){ if(mode === "resize"){ if(gantt.getState().drag_from_start === true) { // changing the start date of a task } else { // changing the end date of a task } } return true; });
您可以使用以下選擇器定位調整大小手柄:
.gantt_task_drag[data-bind-property="start_date"] .gantt_task_drag[數據綁定屬性=“結束日期”]以下 CSS 可用于禁用調整任務開始日期的大?。?
.gantt_task_drag[data-bind-property="start_date"]{ display: none !important; }同樣,防止調整結束日期的大小如下所示:
.gantt_task_drag[data-bind-property="end_date"]{ display: none !important; }另一種方法是使用onBeforeTaskDrag事件。從處理程序返回false將阻止調整大小:
gantt.attachEvent("onBeforeTaskDrag", function(id, mode, e){ if(mode === "resize"){ if(gantt.getState().drag_from_start === true) { return false; } else { // changing the end date of a task } } return true; });
DHTMLX Gantt享有超十年聲譽,支持跨瀏覽器和跨平臺,性價比高,可滿足項目管理控件應用的所有需求,是最完善的甘特圖圖表庫。
慧都2022年終狂歡火熱進行中,全場產品超低價,DHTMLX全系產品享8.8折!了解更多活動詳情,歡迎訪問慧都網咨詢。
甘特圖控件交流群:764148812 歡迎進群交流討論
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn