Our state of the art Gantt chart


Post by shaveta »

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?

Screenshot 2022-12-07 at 10.48.47 AM.png
Screenshot 2022-12-07 at 10.48.47 AM.png (179.51 KiB) Viewed 469 times

Post by tasnim »

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

Attachments
chrome_EdAMsASuAu.png
chrome_EdAMsASuAu.png (40.21 KiB) Viewed 465 times

Post by shaveta »

tasnim wrote: Wed Dec 07, 2022 7:41 am

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

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

Screenshot 2022-12-07 at 11.33.38 AM.png
Screenshot 2022-12-07 at 11.33.38 AM.png (182.64 KiB) Viewed 463 times

Post by arcady »

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;
};

Post by shaveta »

arcady wrote: Wed Dec 07, 2022 1:31 pm

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;
};

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?


Post by arcady »

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.


Post Reply