커스텀 엘리먼트 생성하기
라이트박스에 커스텀 컨트롤을 추가하려면 다음과 같이 새로운 객체를 정의합니다:
gantt.form_blocks["my_editor"]={
render:function(sns){ //sns - 섹션의 설정 객체
return "html code of the editor here";
},
set_value:function(node,value,task,section){
//node - 위에서 정의한 html과 연관된 html 엘리먼트
//value - map_to 속성에 의해 정의된 값
//task - 태스크 객체
//section- 섹션의 설정 객체
... 값을 엘리먼트에 설정하는 코드 ...
},
get_value:function(node,task,section){
//node - 위에서 정의한 html과 연관된 html 엘리먼트
//task - 태스크 객체
//section - 섹션의 설정 객체
return "에디터에서 현재 값 반환";
},
focus:function(node){
//node - 위에서 정의한 html과 연관된 html 엘리먼트
...엘리먼트에 포커스를 주는 코드...
}
}
render 함수에서 반환하는 HTML 코드 내에서는 셀프 클로징 태그를 사용하지 않는 것이 좋습니다. 일부 브라우저에서 파싱 문제가 발생할 수 있습니다:
//이것은 잘못된 예시입니다
render:function(){
return "<div id='box'/>";
}
//대신, 여는 태그와 닫는 태그를 사용하세요:
render:function(){
return "<div id='box'></div>"; // 권장
}
Custom control in the lightbox
라이트박스 컨트롤은 다음과 같은 메서드로 구성됩니다:
- render (sns): string - 섹션을 위한 HTML 엘리먼트의 문자열을 반환합니다
- sns - (LightboxSection) - 섹션의 설정 객체
- set_value (node, value, task, section): any - Task 객체의 값을 받아 섹션에 적용합니다
- node - (HTMLElement) - 섹션의 HTML과 연관된 HTML 엘리먼트
- value - (any) - map_to 속성에 의해 정의된 값
- task - (Task) - 태스크 객체
- section - (LightboxSection) - 섹션의 설정 객체
- get_value (node, task, section): any - 섹션에서 값을 가져와 Task 객체에 저장합니다
- node - (HTMLElement) - 섹션의 HTML과 연관된 HTML 엘리먼트
- task - (Task) - 태스크 객체
- section - (LightboxSection) - 섹션의 설정 객체
- focus (node): void - 섹션에 포커스를 설정합니다
- node - (HTMLElement) - 섹션의 HTML과 연관된 HTML 엘리먼트
두 개의 입력 필드를 가진 커스텀 에디터
두 개의 입력 필드를 가진 커스텀 에디터를 만드는 예시입니다:

gantt.form_blocks["my_editor"] = {
render: function (sns) {
return "<div className='dhx_cal_ltext' style='height:60px;'>"+
"Text <input className='editor_description' type='text'/>"+
"
Holders <input className='editor_holders' type='text'/>"+
"</div>";
},
set_value: function (node, value, task) {
node.querySelector(".editor_description").value = value || "";
node.querySelector(".editor_holders").value = task.users || "";
},
get_value: function (node, task) {
task.users = node.querySelector(".editor_holders").value;
return node.querySelector(".editor_description").value;
},
focus: function (node) {
var a = node.querySelector(".editor_description");
a.select();
a.focus();
}
};
gantt.config.lightbox.sections = [
{ name:"description", height:200, map_to:"text", type:"my_editor", focus:true},
{ name:"time", height:72, type:"duration", map_to:"auto"}
];
Custom control in the lightbox
커스텀 서드파티 에디터
여러 값을 선택할 수 있는 커스텀 멀티셀렉트 컨트롤을 만드는 것도 가능합니다.
예를 들어, jQuery Chosen plugin을 기반으로 한 컨트롤 을 사용하여 하나의 태스크에 여러 리소스를 할당할 수 있습니다. 기본 Gantt resource control과 달리, 이 컨트롤은 리소스의 수량 지정 없이 단순히 리소스만 할당합니다. 간단한 컨트롤이 필요한 경우에 적합합니다.

Gantt 차트에 jQuery Chosen 기반 컨트롤을 통합하려면:
- 필요한 소스 파일을 페이지에 포함하세요
<script
src="https://code.jquery.com/jquery-3.3.1.min.js?v="5.2.4""
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossOrigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.jquery.js?v="5.2.4""></script>
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.8.7/chosen.css?v="5.2.4"">
- 컨트롤 로직을 정의하세요
gantt.form_blocks["multiselect"] = {
render: function (sns) {
var height = (sns.height || "23") + "px";
var html = "<div className='gantt_cal_ltext gantt_cal_chosen gantt_cal_multiselect'"+
"style='height:"+ height + ";'><select data-placeholder='...'"+
"class='chosen-select' multiple>";
if (sns.options) {
for (var i = 0; i < sns.options.length; i++) {
if(sns.unassigned_value !== undefined && sns.options[i].key==sns.unassigned_value){
continue;
}
html+="<option value='" +sns.options[i].key+ "'>"+sns.options[i].label+"</option>";
}
}
html += "</select></div>";
return html;
},
set_value: function (node, value, ev, sns) {
node.style.overflow = "visible";
node.parentNode.style.overflow = "visible";
node.style.display = "inline-block";
var select = $(node.firstChild);
if (value) {
value = (value + "").split(",");
select.val(value);
}
else {
select.val([]);
}
select.chosen();
if(sns.onchange){
select.change(function(){
sns.onchange.call(this);
})
}
select.trigger('chosen:updated');
select.trigger("change");
},
get_value: function (node, ev) {
var value = $(node.firstChild).val();
//value = value ? value.join(",") : null
return value;
},
focus: function (node) {
$(node.firstChild).focus();
}
};
- *type:"multiselect"*로 라이트박스 섹션에 컨트롤을 추가하세요
gantt.config.lightbox.sections = [
{name:"description",height:38,map_to:"text",type:"textarea",focus: true},
{name:"owner",height:60, type:"multiselect", options:gantt.serverList("people"),
map_to:"owner_id", unassigned_value:5 },
{name: "time", type: "duration", map_to: "auto"}
];
unassigned_value 속성은 선택할 수 없는 리소스를 숨깁니다. 이 속성에 제외할 리소스의 ID를 설정하세요. 위 예시에서는 id="5인" 리소스가 컨트롤에 나타나지 않습니다.