Premium support for our pure JavaScript UI components


Post by cubrilo »

I am trying to customize the children field in the ResourceModel class for the case of Tree scheduler. I have groups as parents and they are containing users. I want to be able to customize the children field to be be of type Array<User> and to be able to switch the default property names same way I can do it for the parent class, eg.

{ name: 'resourceId', dataSource: 'technicianNumber' }

Post by mats »

To have heterogenous trees, please override this method and choose the Model class to create: https://bryntum.com/docs/scheduler/#Core/data/Store#function-createRecord

/**
 * Creates a model instance, used internally when data is set/added. Override this in a subclass to do your own custom
 * conversion from data to record.
 * @param {Object} data Json data
 * @param {Boolean} [skipExpose] Supply true when batch setting to not expose properties multiple times
 * @category Records
 */
createRecord(data, skipExpose = false) {
    return new this.modelClass(data, this, null, skipExpose);
}

Post by cubrilo »

Just to confirm that I understood correctly, you meant on something like this:

export default class CustomResourceStore extends ResourceStore {
    createRecord(data, skipExpose = false) {
        data.users.forEach(user => {
            user.id = user.personnelNumber;
            user.role = data.name;
        });
        data.children = data.users;
        return new this.modelClass(data);
    }
}

Implementing custom store and setting all the missing props here and then just passing it back to scheduler?
I didn't find

this.modelClass(data, this, null, skipExpose);

from your example with so many parameters.
Is this the solution that you suggested or is there some other way?


Post by alex.l »

HI cubrilo,

this.modelClass just contains the model class that has been specified to use in that store. https://bryntum.com/docs/scheduler/#Core/data/Store#config-modelClass

These params are declared in Model base class constructor and used for internal purposes, so not documented.
If you want to have different model classes in you array, you need to create records for that array by you own.
I see only data mapping in your code snippet. If it's enough for you, that's fine. As I understood from your first question, you want to create a User class instances (that I hope you defined somewhere) inside that array, so create instances in your loop.

All the best,
Alex

All the best,
Alex


Post Reply