Hi,
How to set the duration field to allow days, months, and hours units. I have tried to add decimalPrecision and allowedUnits in the Task model but it's not reflecting. Anything wrong?
To achieve that, you just need to set https://bryntum.com/products/gantt/docs/api/Gantt/model/TaskModel#field-durationUnit to what ever unit you want
And then set the duration
tasnim wrote: ↑Wed Dec 07, 2022 7:41 amTo achieve that, you just need to set https://bryntum.com/products/gantt/docs/api/Gantt/model/TaskModel#field-durationUnit to what ever unit you want
And then set the duration
Thanks, Tasnim!!
I want to restrict duration unit to not set to seconds/milliseconds, so I have used allowedUnits. Do I need to set this property at durationunit level?
Also for duration to be rounded, do I need to set decimalPrecision in the way shown in the attached screenshot? I don't want the duration to be in decimals but right now it goes like 1.23345 days
You can override DateHelper.parseDuration method. Like here for example it forces to use day
unit only:
// remember original function
const origFunction = DateHelper.parseDuration;
// override to force using of days always
DateHelper.parseDuration = function (value, allowDecimals = true, defaultUnit) {
const result = origFunction.call(this, ...arguments);
// regardless of what unit was provided we treat it as day
result.unit = 'day';
return result;
};
arcady wrote: ↑Wed Dec 07, 2022 1:31 pmYou can override DateHelper.parseDuration method. Like here for example it forces to use
day
unit only:// remember original function const origFunction = DateHelper.parseDuration; // override to force using of days always DateHelper.parseDuration = function (value, allowDecimals = true, defaultUnit) { const result = origFunction.call(this, ...arguments); // regardless of what unit was provided we treat it as day result.unit = 'day'; return result; };
Thanks, Arcady! Can't we make use of allowed duration units, from the documentation I am assuming if allowedUnits property is set we can allow 3 or 4 options for units as needed
https://www.bryntum.com/products/gantt/docs/api/Core/widget/DurationField#config-allowedUnits
Also is setting allowDecimals = false will not allow to enter/calculate duration in decimals?
allowedUnits
is a widget config. It configures UI input field. The one that is used in task editor or duration column editor. So it means nothing for https://www.bryntum.com/products/gantt/docs/api/Core/data/field/NumberDataField which represents duration field on TaskModel class.
Yes you can change allowDecimals
argument in the provided override and pass it as false
to origFunction
and then ..when parsing provided duration string ..it will not support non-decimal values.