Our state of the art Gantt chart


Post by kalai »

Adding fields inside the static fields getter helps to add additional fields for manual entry. Is there a way we can add calculated fields in TaskModel? Like calculating cost based on price per unit and conversation as per base currency. I'm not sure Bruntum would be interested in building these calculation as part of the code library. Leaving these things to consumer would be good idea to ensure the slim core engine.

Actual:

class MyTaskModel extends TaskModel {
  static get fields() {
      return [
          { name: 'importantDate', type: 'date' }
      ]
  }
}

Expectation:

class MyTaskModel extends TaskModel {
  static get fields() {
      return [
          { name: 'importantDate', type: 'date', calculateFunction: (args)=>{} }
      ]
  }
}

Post by mats »

We have a ticket open for adding this, please track this for updates: https://github.com/bryntum/support/issues/4025

Thanks for your feedback :)


Post by kalai »

Hello @mats,

Thanks for quick response. As I can see the ticket has no update since 21 Feb. We really need this feature to use scheduler in our application. Can you suggest any workaround or solution to address this issue?

Thanks


Post by alex.l »

I've asked product management to review the priority of that task again.
For now it's possible to calculate field only for initial data.
You could try to set persist: false for your field to not pass its data to server, and define https://bryntum.com/docs/gantt/api/Core/data/field/DataField#function-convert

export default class Task extends TaskModel {
   static get fields() {
       return [
           {
               name    : 'total',
               persists : false,
               convert : value => {
                   return this.amount * this.price
               }
           }
       ];
   }
}

Or define custom getter

// here you can extend our default Task class with your additional fields, methods and logic
export default class Task extends TaskModel {

static $name = 'Task';

static get fields() {
    return [
        'status' // For status column
    ];
}

get isLate() {
    return !this.isCompleted && this.deadlineDate && Date.now() > this.deadlineDate;
}

get status() {
    let status = 'Not started';

    if (this.isCompleted) {
        status = 'Completed';
    }
    else if (this.isLate) {
        status = 'Late';
    }
    else if (this.isStarted) {
        status = 'Started';
    }

    return status;
}
}

It's also possible to display calculated data using custom renderer for a column, but it will be UI level, not data level.

All the best,
Alex


Post by kalai »

Thanks Alex. UI level getters would not help us much but it's better than nothing. In think, we had struggle with doing the calculation before sending data to database.

Our customers complains that, saving takes more time. (Imagine project with 500K+ Tasks) We also do some calculation on load. (We cannot use UI getter solution to make our customisation consistent with how & where we do calculations)

Hoping that we could have the calculated fields at data level from Bryntum


Post Reply