Resource Assignments Control
This functionality is available in the Gantt PRO edition only.
An extended control used to assign multiple resources and their quantity to a task.
Here is an example of the Resource Assignments control with the default configuration:

gantt.config.lightbox.sections = [
{ name: "description", height: 38, map_to: "text", type: "textarea", focus: true },
{ name: "resource_selector", label: "Resources", type: "resource_selector", map_to: "auto" },
{ name: "time", type: "duration", map_to: "auto" }
];
You can configure the resource grid columns of the control and provide the necessary resource options:

// resource options
const usageMap = [
{ key: 1, label: "wood", text: "wood", unit: "box" },
{ key: 2, label: "water", text: "water", unit: "liter" },
{ key: 3, label: "grain", text: "grain", unit: "lbs" }
];
// helper editors
const selectResEditor = { type: "select", map_to: "resource_id", options: usageMap };
const numberEditor = { type: "number", map_to: "value", min: 0, max: 100 };
// resource grid columns config
const resourceLightboxConfig = {
columns: [
{
name: "resource",
label: "Resource",
editor: selectResEditor
// more column's options
},
{
name: "units",
label: "Units",
editor: numberEditor,
// more column's options
},
{
name: "delete",
label: "Delete",
// more column's options
}
]
};
gantt.config.lightbox.sections = [
{ name: "description", height: 38, map_to: "text", type: "textarea", focus: true },
{ name: "time", type: "duration", map_to: "auto" },
{ name: "resource_selector", type: "resource_selector", map_to: "auto", /*!*/
config: resourceLightboxConfig } /*!*/
];
gantt.locale.labels.section_resource_selector = "Resources";
You can also create a custom control to assign multiple resources to a task.
Initialization
To add the resource_selector control to the lightbox, follow the steps below:
1. Add a section to the lightbox configuration:
gantt.config.lightbox.sections = [
{ name: "description", height: 38, map_to: "text", type: "textarea", focus: true },
{ name: "resource_selector", type: "resource_selector", map_to: "auto" },
{ name: "time", type: "duration", map_to: "auto" }
];
2. Set a label for the section:
gantt.locale.labels.section_resource_selector = "Resources";
Properties
The following properties are mostly important and commonly set for the resource_selector control:
- name - (string) the section's name
- map_to - (string) the name of a data property that will be mapped to the section
- type - (string) the type of the section control
- label - (string) the section's label
- config - (object) the resource grid config in the lightbox to display required columns
- templates - (object) templates for the resource grid in the lightbox
The initial start_date, end_date, and duration properties may have null values. If so, they will be initialized using the corresponding values from the task object.
Configuring resource grid columns in the lightbox
The default configuration of columns of the resource table in the lightbox is given below:
// helper editors
const selectResEditor = {
type: "select", map_to: "resource_id", options: gantt.serverList("resourceOptions")
};
const numberEditor = { type: "number", map_to: "value", min: 0, max: 100 };
const dateToStr = gantt.date.date_to_str("%d-%m-%Y");
const resourceStore = gantt.getDatastore(gantt.config.resource_store);
// default columns definition
const defaultResourceLightboxConfig = {
scale_height: 35, // height of the grid scale
row_height: 35, // height of assignment rows
// configures the columns of the grid
columns: [
{
name: "resource", label: "Resource", align: "center", width: 80,
editor: selectResEditor, template: function (assignment) {
let defaultValue = "Unassigned";
const resource = resourceStore .getItem(assignment.resource_id);
return resource ? resource.text : defaultValue;
}
},
{
name: "hours/Day", label: "Hours/Day", align: "center", width: 70,
editor: numberEditor, template: function (assignment) {
return assignment.value ? +assignment.value : ``;
}
},
{
name: "start", label: "Start", align: "center", width: 100,
template: function (assignment) {
return assignment.start_date ? dateToStr(assignment.start_date) : ``;
}
},
{
name: "end", label: "End", align: "center", width: 100,
template: function (assignment) {
return assignment.end_date ? dateToStr(assignment.end_date) : ``;
}
},
{
name: "duration", label: "Duration", align: "center", width: 80,
template: function (assignment) {
if (assignment.duration) {
return `${assignment.duration} day${assignment.duration == 1 ? '' : 's'}`;
} else {
return ``;
}
}
},
{
name: "delete", label: "Delete", align: "center", width: 80,
template: function (assignment) {
return `<div
data-assignment-id='${assignment.id}'
data-assignment-delete='${assignment.id}'
className='dhx_gantt_icon dhx_gantt_icon_delete'
>
</div>`;
}
}
],
//Configures the default adding assignment(assignment that will be added by "Add Assignment button")
resource_default_assignment: {
duration: null,
value: 8,
start_date: null,
end_date: null,
mode: "default"
}
};