项目管理软件dhtmlxGantt配置教程(十五):突出展示时间段

本文介绍了如何在dhtmlxGantt中通过timeline_cell_class和scale_cell_class模板来突出显示时间线上的特定时间段,如周末。利用这些模板和isWorkTime函数,可以更好地在甘特图中区分工作时间和非工作时间。

为了让用户注意特定的时间段,您可以突出显示它们。

  • 要突出显示时间线区域的单元格,请使用timeline_cell_class模板。
  • 要突出显示时间线时间刻度的单元格,请使用scale_cell_class模板。

模板是一个函数,它遍历所有日期并将指定的 CSS 类应用于相关单元格。

例如,您可以突出显示周末以直观地将比例划分为周:

<style>
.weekend{ background: #f4f7f4 !important;}
</style>
gantt.templates.scale_cell_class = function(date){
    if(date.getDay()==0||date.getDay()==6){
        return "weekend";
    }
};
gantt.templates.timeline_cell_class = function(task,date){
    if(date.getDay()==0||date.getDay()==6){ 
        return "weekend" ;
    }
};
gantt.init("gantt_here");

请注意,在使用工作时间计算时,您可以使用isWorkTime而不是硬编码值:

gantt.config.work_time = true;
 
gantt.templates.scale_cell_class = function(date){
    if(!gantt.isWorkTime(date)){
        return "weekend";
    }
};
gantt.templates.timeline_c
dhtmlxGantt是一个强大的JavaScript甘特图库,广泛应用于项目管理软件中。本文将介绍如何调整dhtmlxGantt中的网格行大小,以提高用户体验和界面美观度。 ### 调整网格行大小的步骤 1. **引入dhtmlxGantt库**: 首先,确保你已经引入了dhtmlxGantt的CSS和JS文件。 ```html <link rel="stylesheet" href="dhtmlxgantt.css" type="text/css"> <script src="dhtmlxgantt.js"></script> ``` 2. **初始化甘特图**: 在HTML中添加一个容器用于初始化甘特图。 ```html <div id="gantt_here" style="width:100%; height:100%;"></div> ``` 然后在JavaScript中初始化甘特图。 ```javascript gantt.init("gantt_here"); ``` 3. **调整行高**: 使用`gantt.config.row_height`属性来设置网格行的高度。默认值通常是28像素。 ```javascript gantt.config.row_height = 40; // 设置行高为40像素 gantt.init("gantt_here"); gantt.parse(demo_tasks); // 解析任务数据 ``` 4. **调整列宽**: 你也可以通过设置列的宽度来调整网格的布局。 ```javascript gantt.config.scale_unit = "month"; gantt.config.date_scale = "%F, %Y"; gantt.config.scale_height = 60; gantt.config.min_column_width = 50; gantt.init("gantt_here"); gantt.parse(demo_tasks); ``` ### 完整示例 以下是一个完整的示例,展示了如何调整dhtmlxGantt中的网格行大小: ```html <!DOCTYPE html> <html> <head> <title>dhtmlxGantt调整网格行大小示例</title> <link rel="stylesheet" href="dhtmlxgantt.css" type="text/css"> <script src="dhtmlxgantt.js"></script> <script> gantt.config.row_height = 40; // 设置行高为40像素 gantt.config.scale_unit = "month"; gantt.config.date_scale = "%F, %Y"; gantt.config.scale_height = 60; gantt.config.min_column_width = 50; gantt.init("gantt_here"); gantt.parse({ data: [ {id: 1, text: "任务 1", start_date: "2023-01-01", duration: 5}, {id: 2, text: "任务 2", start_date: "2023-01-06", duration: 7} ], links: [] }); </script> </head> <body> <div id="gantt_here" style="width:100%; height:100%;"></div> </body> </html> ``` ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值