end_date
Description
定义时间刻度的结束点
end_date: Date | undefined
Example
gantt.config.start_date = new Date(2018, 08, 10);
gantt.config.end_date = new Date(2018, 08, 20);
gantt.init("gantt_here");
Details
注释
end_date 选项应与 start_date 选项一起使用才能生效。
- 当同时设置了 start_date 和 end_date 时,超出该范围的任务将不会显示在图表上。
- start_date 和 end_date 的初始值可以通过 init 方法的可选参数提供。
- start_date 和 end_date 中的设置优先于 fit_tasks。若要结合这些配置,您需要通过编程控制时间刻度。
以下示例展示了如何动态扩展时间范围:
gantt.attachEvent("onLightboxSave", function(id, task, is_new){
const taskStart = task.start_date;
const taskEnd = task.end_date;
const scaleStart = gantt.config.start_date;
const scaleEnd = gantt.config.end_date;
// 如果任务超出当前范围
if(scaleStart > taskEnd || scaleEnd < taskStart ){
// 调整时间刻度边界
gantt.config.end_date=new Date(Math.max(taskEnd.valueOf(), scaleEnd.valueOf()));
gantt.config.start_date=new Date(Math.min(taskStart.valueOf(),scaleStart.valueOf()));
gantt.render();
}
return true;
});
或者,您也可以添加校验以防止保存超出范围的任务:
gantt.attachEvent("onLightboxSave", function(id, task, is_new){
const taskStart = task.start_date;
const taskEnd = task.end_date;
const scaleStart = gantt.config.start_date;
const scaleEnd = gantt.config.end_date;
// 验证任务是否超出允许范围
if(scaleStart > taskEnd || scaleEnd < taskStart ){
gantt.message({
type:"warning",
text:"警告!任务超出日期范围!",
expire:5000
});
return false;
}
return true;
});
Related API
Related Guides
Need help?
Got a question about the documentation? Reach out to our technical support team for help and guidance. For custom component solutions, visit the Services page.