Our blazing fast Grid component built with pure JavaScript


Post 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


Post by mats »

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


Post 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

Attachments
bryntum-scheduler-pro.zip
(386.76 KiB) Downloaded 19 times

Post 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.

All the best,
Alex


Post 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.

Attachments
orderedChildrenError.png
orderedChildrenError.png (34.48 KiB) Viewed 265 times

Post 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.


Post by corner4 »

Done

What about #1?


Post 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.

All the best,
Alex


Post by corner4 »

Hi Alex,

thank you, looks like integrating

persist: true

in our ModelClass Fields does the trick.

BR


Post Reply