Available only in PRO Edition
This functionality is available in the PRO Edition only.
A complex control used to assign multiple resources and their quantity to a task.
gantt.config.lightbox.sections = [
{name: "description", height: 38, map_to: "text", type: "textarea", focus: true},
{name:"owner",height:60, type:"resources", default_value:8}, {name: "time", type: "duration", map_to: "auto"}
];
Related sample: Assign multiple resources
or
gantt.config.lightbox.sections = [
{ name:"description",height:38,map_to:"text",type:"textarea",focus:true },
{ name:"time",type:"duration",map_to:"auto" },
{ name:"rooms",type:"resources",map_to:"rooms", options:[ { key: 1, label: "room 1", unit: "hours" }, { key: 2, label: "room 2", unit: "hours" }, { key: 3, label: "room 3", unit: "hours" } ] } ];
gantt.locale.labels.section_rooms = "Rooms";
Related sample: Resources control
You can also create a custom control to assign multiple resources to a task.
To add the resources 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:"time",type:"duration",map_to:"auto" },
{ name:"rooms",type:"resources" } ];
2. Set a label for the section:
gantt.locale.labels.section_resources = "Rooms";
Related sample: Resources control
The following properties are mostly important and commonly set for the resources control (see the full list here):
By default the resource control is mapped to the property specified in the resource_property config, so the map_to option can be omitted.
By default the resource control is automatically populated from the resource datastore via the gantt.serverList("resourceOptions")
collection. You only need to specify the options list manually if you want to change the default behavior.
Starting from v8.0, the resource control gets options from the resource Datastore by default.
If you use the default resource Datastore created by Gantt, the resource control initialized without the options parameter, will be connected to the gantt.serverList("resourceOptions") collection. This collection will be populated with the resources from the resource datastore. You can access options by code:
const options = gantt.serverList("resourceOptions");
Note, the options array will be empty before the resources are loaded into the datastore.
You can also update this collection using the custom list of options:
gantt.updateCollection("resourceOptions", [...]);
Note, that if you load resources into the gantt after that, the gantt will update this collection and overwrite your changes.
If you want to control which resources go to the lightbox, you can redefine the gantt.config.resources.lightbox_resources config:
gantt.config.resources = {
lightbox_resources: function selectResourceControlOptions(resources){
const lightboxOptions = [];
resources.forEach(function(res) {
if (!gantt.$resourcesStore.hasChild(res.id)) {
const copy = gantt.copy(res);
copy.key = res.id;
copy.label = res.text;
lightboxOptions.push(copy);
}
});
return lightboxOptions;
}
};
If you create the resource datastore manually, you need to populate the resource control with the options yourself.
Generally, to set values for the resources control, use the options parameter:
gantt.config.lightbox.sections = [
{ name:"rooms",type:"resources",map_to:"rooms",
options:[
{ key: 1, label: "room 1", unit: "hours" },
{ key: 2, label: "room 2", unit: "hours" },
{ key: 3, label: "room 3", unit: "hours" }
]
}
];
Items in the options parameter have 3 mandatory properties:
To populate the control from the server, set the options option to the value returned by the serverList method:
gantt.config.lightbox.sections = [
{name: "description", height: 38, map_to: "text", type: "textarea", focus: true},
{name: "resources", type: "resources", map_to: "owner_id", default_value:8,
options: gantt.serverList("resourceOptions")},
{name: "time", type: "duration", map_to: "auto"}
];
gantt.init("gantt_here");
gantt.load("/data");
The contents of gantt.serverList("resourceOptions")
can be defined when the options become available using the updateCollection method:
gantt.updateCollection("resourceOptions", [
{ key: 1, label: "room 1", unit: "hours" },
{ key: 2, label: "room 2", unit: "hours" },
{ key: 3, label: "room 3", unit: "hours" }
])
Related sample: Assign multiple resources
Back to top