Gantt 스타일 작업하기
dhtmlxGantt는 외관을 사용자 정의할 수 있는 다양한 옵션을 제공합니다. 전체 Gantt 차트의 모양을 변경하려면 미리 정의된 스킨을 적용할 수 있고, 또는 작업, 링크, 스케일, 그리드 등 개별 요소들의 스타일을 세밀하게 조정할 수 있습니다.
이 가이드는 Gantt 차트의 다양한 부분을 스타일링하는 일반적인 방법을 모아, 관련 문서를 더 쉽게 탐색할 수 있도록 도와줍니다. 각 요소별 자세한 정보는 관련 문서를 참고하세요.
그리드 스타일링
그리드 영역의 스타일은 관련 그리드의 템플릿를 통해 수정할 수 있습니다.
그리드 컬럼 헤더
grid_header_class 템플릿을 사용하면 그리드 컬럼 헤더에 사용자 지정 스타일을 적용할 수 있습니다. 예를 들어, 특정 헤더의 배경색을 변경하려면 다음과 같이 할 수 있습니다:
<style>
.updColor{
background-color:#ffeb8a!important;
}
</style>
gantt.templates.grid_header_class = function(columnName, column){
if(columnName == 'duration' ||columnName == 'text')
return "updColor";
};

Related example: Styling Headers of Grid Columns
그리드 헤더에 커스텀 요소 추가
버튼, 아이콘, 입력창 등 커스텀 요소를 그리드 헤더에 추가할 수 있습니다. 이를 위해서는 gantt.config.columns 설정 옵션의 label 속성에 해당 요소의 HTML을 지정하면 됩니다:
gantt.config.columns = [
{name:"add", label:"", width:50, align:"left" },
{name:"text", label:"<div className='searchEl'>Task name <input id='search' type='text'"+ /*!*/
"placeholder='Search tasks...'></div>", width:250, tree:true}, /*!*/
// other columns
];
아래는 검색 기능이 구현된 예시입니다:
var inputEl = document.getElementById('search');
inputEl.oninput = function(){
gantt.refreshData();
}
function hasSubstr(parentId){
var task = gantt.getTask(parentId);
if(task.text.toLowerCase().indexOf(inputEl.value.toLowerCase() ) !== -1)
return true;
var child = gantt.getChildren(parentId);
for (var i = 0; i < child.length; i++) {
if (hasSubstr(child[i]))
return true;
}
return false;
}
gantt.attachEvent("onBeforeTaskDisplay", function(id, task){
if (hasSubstr(id))
return true;
return false;
});

Related example: Custom Elements in Grid Header
그리드 헤더에 아이콘 및 이미지 삽입
헤더에 이미지나 아이콘을 넣으려면 label 속성에 해당 요소의 HTML을 추가하면 됩니다:
var textLabel = [
"<div className='gantt-text-label'>"+
"<img src='http://docs.dhtmlx.com/scheduler/assets/index/icon1.png'>"+
"<span>Text</span>" +
"</div>"
].join("");
gantt.config.columns = [
{name: "text", label:textLabel,tree: true, width: '*', resize: true},
{name: "start_date", align: "center", resize: true},
{name: "duration", align: "center"},
{name: "add", width: 44}
];
Related example: Images in Grid Header: Columns Config
또는, CSS의 .gantt_grid_head_
.gantt_grid_head_text {
background-image:url('http://docs.dhtmlx.com/scheduler/assets/index/icon1.png');
background-repeat:no-repeat;
}

Related example: Images in Grid Header:CSS
그리드 헤더의 멀티라인 텍스트
그리드 셀/헤더에 여러 줄을 표시하는 방법 섹션의 예제를 참고하세요.
그리드 행의 배경색
grid_row_class 템플릿을 사용해 모든 그리드 행 또는 특정 작업이 포함된 행의 배경색을 지정할 수 있습니다. 예를 들어, 특정 행의 배경색을 변경하려면:
<style>
.updColor{
background-color:#ffeb8a!important;
}
</style>
gantt.templates.grid_row_class = function(start, end, task){
if(task.id == 12)
return "updColor";
};

Related example: Coloring Grid Rows
그리드 행 마우스오버 색상
마우스를 올렸을 때 그리드 행을 강조하려면 다음 스타일을 적용하세요:
.gantt_grid_data .gantt_row.odd:hover, .gantt_grid_data .gantt_row:hover,
.gantt_grid_data .gantt_row.gantt_selected,
.gantt_grid_data .gantt_row.odd.gantt_selected,
.gantt_task_row.gantt_selected{
background-color: cyan;
}

Related example: Coloring Grid Rows on Hover
그리드 컬럼 커스터마이징
dhtmlxGantt는 gantt.config.columns 설정 옵션의 template 속성을 통해 그리드 컬럼의 기본 모양을 사용자 정의할 수 있습니다.
template 속성은 데이터 항목 객체를 받아 최종 컨텐츠를 반환하는 함수입니다. 이를 통해 거의 모든 형태의 컨텐츠 커스터마이징이 가능합니다. 예를 들어, 그리드 행의 텍스트 색상을 변경하거나, 컬럼에 커스텀 요소를 삽입할 수 있습니다.
그리드 행의 텍스트 색상
작업의 우선순위에 따라 텍스트 색상을 지정하려면 다음과 같이 할 수 있습니다:
gantt.config.columns="["
{name:"text", label:"Task name", tree:true, width:230, template:myFunc }, /*!*/
{name:"start_date", label:"Start time", align: "center" },
{name:"duration", label:"Duration", align: "center" }
];
function myFunc(task){
if(task.priority ==1)
return "<div className='important'>"+task.text+" ("+task.users+") </div>";
return task.text+" ("+task.users+")";
};

그리드 컬럼의 커스텀 요소
버튼이나 입력창 등 커스텀 요소를 그리드 컬럼에 추가하려면, 해당 컬럼의 template 속성에 요소의 HTML을 지정하세요:
var colContent = function (task) {
return ('<i className="fa gantt_button_grid gantt_grid_edit fa-pencil"'+
'onclick="clickGridButton(' + task.id + ', 'edit')"></i>' +
'<i className="fa gantt_button_grid gantt_grid_add fa-plus"'+
'onclick="clickGridButton(' + task.id + ', 'add')"></i>' +
'<i className="fa gantt_button_grid gantt_grid_delete fa-times"'+
'onclick="clickGridButton(' + task.id + ', 'delete')"></i>');
};
gantt.config.columns = [
{name: "text", tree: true, width: '*', resize: true},
{name: "start_date", align: "center", resize: true},
{name: "duration", align: "center"},
{name: "buttons", label: colHeader, width: 75, template: colContent} /*!*/
];

긴 텍스트를 말줄임표로 표시
Gantt는 그리드 행에서 긴 텍스트를 자동으로 축약해 보여줍니다.
버전 7.0부터는 .gantt_tree_content CSS 클래스를 재정의하여 말줄임표로 표시할 수 있습니다:
<style>
.gantt_tree_content {
overflow:hidden;
text-overflow: ellipsis;
}
</style>
gantt.init("gantt_here");

Related example: Truncate long text with ellipsis
그리드 셀 내 멀티라인 텍스트
그리드 셀/헤더에 여러 줄을 표시하는 방법 섹션의 예제를 참고하세요.
스케일 스타일링
스케일의 스타일은 타임라인 영역의 관련 템플릿으로 제어합니다.
스케일 행
scale_row_class 템플릿을 사용해 스케일 행의 스타일을 지정할 수 있습니다. 예를 들어, 배경색을 지정하려면:
<style>
.updColor{
background-color:#ffeb8a!important
}
</style>
gantt.templates.scale_row_class = function(scale){
return "updColor";
}

Related example: Styling Row of the Scale
스케일 셀
scale_cell_class 템플릿을 사용해 특정 스케일 셀을 스타일링할 수 있습니다. 예를 들어, 주말을 강조하려면:
gantt.templates.scale_cell_class = function(date){
if(date.getDay()==0||date.getDay()==6){
return "updColor";
}
};

Related example: Styling Separate Cells on the Scale
자세한 내용은 스케일 설정하기 및 타임 슬롯 하이라이트하기를 참고하세요.