Page 1 of 1

Model#toJSON doesn't populate field that added dynamically

Posted: Fri Aug 05, 2022 10:46 am
by takafumi ohtake

Hi,

I use Core.data.Model#toJSON.
However, when I add fields with Core.data.Model#addField, the added field values is absent in the returned json.

Is there a way to include the added field in json?

CustomTaskModel.addField({
   name: 'custom_1',
   type: 'string',
});

record['custom_1'] = 'test';
console.log(record['custom_1']); // output: 'test'
console.log(record.toJSON()); // custom_1 is absent


Re: Model#toJSON doesn't populate field that added dynamically

Posted: Fri Aug 05, 2022 11:37 am
by takafumi ohtake

In addition, I found another issue.
When I add a aggregate type column dynamically, parent rows doesn't refresh automatically.
It can be reproduced with the demo https://bryntum.com/examples/gantt/aggregation-column/ using the code below.

aggregate_column.mp4
(379.86 KiB) Downloaded 47 times
gantt.project.taskModelClass.addField({name: 'custom_2', type: 'number'});
gantt.columns.add({id: 'custom_2', field: 'custom_2', text: 'Budget', type: 'aggregate'})

Re: Model#toJSON doesn't populate field that added dynamically

Posted: Fri Aug 05, 2022 1:05 pm
by alex.l

Thank you for the report. Fields which dynamically added to Model class will be available only for new created instances and won't be catch by already created records. That causes both problems you reported. I've opened a ticket to fix this moment. https://github.com/bryntum/support/issues/5008