Page 1 of 1

[ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Wed Feb 22, 2023 4:37 pm
by corner4

Hi,

we are currently trying to let the user reorder resources via drag'n'drop using the RowReorder feature in a tree view. To update our entities we are using a CrudManager with autoSync and writeAllFields enabled.

const resourceStore = new ResourceStore({
  id: StoreType.resources,
  modelClass: LaneModel,
  tree: true,
  writeAllFields: true,
});

apiProject = new ApiProjectModel({
  writeAllFields: true,
  supportShortSyncResponse: true,

  resourceStore: this.resourceStore,
  timeRangeStore: this.timeRangeStore,
  eventStore: this.eventStore,
  assignmentStore: this.assignmentStore,
  dependencyStore: this.dependencyStore,
});

export class ApiProjectModel extends ApiTransporter(EmptyEncoder(ProjectModel)) {
  constructor(config?: Partial<ProjectModelConfig>) {
    super(config);
  }

  static get defaultConfig(): Partial<ProjectModelConfig> {
    return {
      autoSync: true,
      autoLoad: false,
      supportShortSyncResponse: false,
      validateResponse: false,
      transport: {
        load: { url: 'load' },
        sync: { url: 'sync' },
      },
    };
  }
}

const ApiTransporter = (Target: typeof SchedulerProjectCrudManagerClass) =>
  class ApiTransporter extends Target {
    constructor(config?: Partial<ProjectModelConfig>) {
      super(config);
    }
  }
}

The problem we encountered is that there is only a single request the first time a resource is reordered and the parentIndex field is missing as well.

Is it possible to enable the requested functionality?

Best regards


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Wed Feb 22, 2023 7:19 pm
by mats

Which version are you using? Could you please upload a simple test case for us that we can debug?


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Tue Feb 28, 2023 5:52 pm
by corner4

We are using Bryntum Scheduler Pro 5.2.10 with Angular 11.0.2

I've created a simple test case with a sync function that produces a fake response. Moving a record to a different position doesn't trigger the sync, not even once.

We have also the problem, that orderedChildren is undefined (in sortOrderedChildren) if we don't use this workaround:

    const newResource = new ResourceModel({
      name: `Resource ${resourcesCount + 1}`,
      parentId: null,
      children: [],
    });

    // temporary? fix for empty orderedChildren
    (newResource as any).orderedChildren = [];

You can add new resources using the cell menu.

Best regards


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Wed Mar 01, 2023 6:43 am
by alex.l

Hi,

SchedulerPro's ResourceModel doesn't have field to keep order, it may display records as is, or using sorter(s) to sort it by some condition(s).
You can implement it yourself, you need to extend ResourceModel with some field to keep position, and listen to https://bryntum.com/products/schedulerpro/docs/api/Grid/feature/RowReorder#event-gridRowDrop and https://bryntum.com/products/schedulerpro/docs/api/Scheduler/data/ResourceStore#event-sort to update that field on time.


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Wed Mar 01, 2023 12:44 pm
by corner4

#1

At first we tried to use a custom field to track the order of the items but with help of the docs we found out there should be a field that keeps track of the order, see:
SchedulerPro.model.ResourceModel#field-orderedParentIndex

Now the question as stated above is, if it is possible to auto trigger the sync when that field changes and to provide that field in the CRUD request.

#2

The second topic i've addressed was that there is an error when initializing a tree node with an empty children array. I've therefore attached a screenshot of the error message, but i could open a separate thread for this issue if you like to.


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Wed Mar 01, 2023 12:54 pm
by mats

The second topic i've addressed was that there is an error when initializing a tree node with an empty children array. I've therefore attached a screenshot of the error message, but i could open a separate thread for this issue if you like to.

Yes please keep one issue/thread, if you can open a new thread with info how to reproduce - we'll get it fixed.


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Wed Mar 01, 2023 1:36 pm
by corner4

Done

What about #1?


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Thu Mar 02, 2023 4:13 am
by alex.l

Hi corner4,

That's not global index as you see in docs, but it's also an option for tree stores to have it in payload. But you won't be able to manually change/set value for that field because it's internal and readOnly.
All you need to have it in payload is to make it peristable.

    project : {
        autoLoad   : true,
        autoSync   : true,
        transport : {
            load : {
                url    : './data/data.json',
            },
            sync : {
                url    : './data/data.json',
            }
        },
        resourceStore : {
            tree : true,
            fields : [{
                name     : 'orderedParentIndex',
                type     : 'number',
                persist  : true // this that need to be changed, by default it false
            }]
        }
    },

After that it will trigger sync on reorder with orderedParentIndex value.


Re: [ANGULAR] RowReorder CRUD Sync (ordered)parentIndex

Posted: Mon Mar 06, 2023 1:08 pm
by corner4

Hi Alex,

thank you, looks like integrating

persist: true

in our ModelClass Fields does the trick.

BR