Page 1 of 2

aggregate column not syncing

Posted: Tue Nov 23, 2021 7:08 pm
by jhughesoneplan

Using your aggregate demo change the project model to:

project = new ProjectModel({
        taskModelClass : MyTaskModel,
autoSync: true,
        transport      : {
            load : {
                url : '../_datasets/launch-saas.json'
            },
            sync: {
                url : '../_datasets/launch-saas.json'
            }
        },
        // This config enables response validation and dumping of found errors to the browser console.
        // It's meant to be used as a development stage helper only so please set it to false for production systems.
        validateResponse : true
    })

Change a cost of a leaf node. Notice it does not send a sync request for any of the parent nodes. This is a current critical issue for us. Is there a quick fix for this?


Re: aggregate column not syncing

Posted: Wed Nov 24, 2021 10:24 am
by Animal

This seems like a bug in the implementation. Here's a ticket to track: https://github.com/bryntum/support/issues/3802


Re: aggregate column not syncing

Posted: Wed Nov 24, 2021 10:39 am
by Animal

As a workaround, you can set up an Override on that class (grid.column.AggregateColumn) of these two methods:

    onRecordUpdate({ record, changes }) {
        const
            me         = this,
            { parent } = record;

        if ((me.field in changes) && parent) {
            parent.set(me.field, me.getRawValue(parent, false));
        }
    }

    getRawValue(record, set = true) {
        let value = 0;

        if (record.children) {
            const
                me       = this,
                fn       = me.function,
                isMathFn = typeof fn === 'string' && typeof Math[fn] === 'function',
                {
                    handler,
                    thisObj
                } = isMathFn ? {
                    handler : Math[fn],
                    thisObj : Math
                } : me.resolveCallback(fn);

            for (let i = 0, { length } = record.children; i < length; i++) {
                value = handler.call(thisObj, value, me.getRawValue(record.children[i]));
            }
            if (set) {
                record.setData(me.field, value);
            }
        }
        else {
            value = record[this.field];
        }
        return value;
    }

Re: aggregate column not syncing

Posted: Wed Nov 24, 2021 11:31 pm
by jhughesoneplan

That is getting me closer. When I edit a field it works. I have a more advanced case. The data is sent to the server it runs a calculation and then returns that calculation for that column. It then sets the column via the sync code and does a roll up. This still does not trigger an new update for the rolled up summary task.


Re: aggregate column not syncing

Posted: Thu Nov 25, 2021 11:45 am
by Animal

I don't really follow. Probably best to set a breakpoint in code and step through it.


Re: aggregate column not syncing

Posted: Mon Nov 29, 2021 5:36 pm
by jhughesoneplan

I have a set up similar to your aggregate demo. Except the cost column is read only and is calculated on the server. You fill out effort and duration and when it saves it calculates cost and returns it. When it gets returned it then rolls up to the summary items. When it rolls up to the summary items it should submit a new sync request to update the summary items. The override only seems to account for manually updating the column. Is there another override I need to make this work


Re: aggregate column not syncing

Posted: Fri Dec 03, 2021 3:29 pm
by alex.l

Do you have all fields you expect to be updated in your data model? How do you update data for that summary items, throw record update? Why do you need to store it on the server if they may be calculated?


Re: aggregate column not syncing

Posted: Fri Dec 03, 2021 6:04 pm
by jhughesoneplan

Yes all fields are in the model. Here is an example

Start with effort at 0 which makes cost 0
Name Effort Cost
Task 1 0 0
Task 2 0 0

Then set Effort on Task 2 to 40
Name Effort Cost
Task 1 40 0
Task 2 40 0

40 gets set for effort on task 2 and task 1 via sync

Cost gets returned for task 2
Name Effort Cost
Task 1 40 0
Task 2 40 500

Cost rolls up to summary
Name Effort Cost
Task 1 40 500
Task 2 40 500

However at this point Task 1 cost does not get submitted back to the server in a sync to be saved. So in the database Task 1 has a cost of 0 which is incorrect. Now if I make cost just an editable field and enter 500 on task 1 it works, just not when the sync updates that field.


Re: aggregate column not syncing

Posted: Mon Dec 06, 2021 11:04 am
by mats

You could try calling https://www.bryntum.com/docs/grid/api/Grid/view/GridBase#function-refreshColumn to manually refresh after each sync?


Re: aggregate column not syncing

Posted: Wed Dec 29, 2021 6:20 pm
by jhughesoneplan

I have 1 more issue related to this. Say you have
Task1 10
---Task2 5
---Task3 5

the fix works if I change Task 3 value, Task1 then syncs. However if you just delete Task3 the total for Task1 goes to 5 but it doesnt sync the change for that task. It only syncs the removal of task3.