Our state of the art Gantt chart


Post by Jerther »

Hi!

I'm trying to add a new relation field to TaskModel. I started with just adding the field (I'll try to keep the code here simple):

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

And I edit it with a combo in the task editor:

{
                type  : 'combo',
                label   : 'Group",
                clearable: true,
                name: 'resourceGroup',
                ref: 'resourceGroupCombo',
                store : this.model.resourceGroupsStore,
                displayField: 'name',
                valueField: 'id',
                async onChange({ source : combo, value, userAction }) {
                   // Code to apply value to record
                }
},

With this, it works mostly fine but elsewhere in my code I'd like to access task.resourceGroup as an object, but it's an integer. And that makes sens.

I think I have to create a new resourceGroupId integer field and declare the resourceGroup field as being a relation in "static get relationConfig()" but I can't find any info on how to do that properly.

Could you provide some direction?

Thanks a lot! :)


Post by sergey.maltsev »

Hi!

Fields are yet simple types only.
So if you want to use resourceGroupId as integer id to some kind of GroupStore you may extend MyTaskModel with a getter.

Something like this.

class MyTaskModel extends TaskModel {
    static get fields() {
        return [
            { name : 'resourceGroupId', type : 'number' }
        ];
    }

get resourceGroup() {
    return resourceGroups.getById(this.resourceGroupId);
}
}

const resourceGroups = new Store(
    { fields : ['id', 'name', 'text'] }
);

Post by Jerther »

Nice! Thanks :)


Post Reply