Our powerful JS Calendar component


Post by codevlabs »

I am trying to sort the resources using a custom field. What am I doing wrong please?

crudManager : {	
			validateResponse:true,		 
			transport : {
				load : {
					url : environment.baseURL + '/1/getCalendar.php?unallocYN=1',
					credentials: "omit",					
					headers: { Authorization: 'Bearer ' + this.constantsService.access_token }										
				},
				sync : {
					url : environment.baseURL + '/1/postCalendar.php',
					credentials: "omit",
					headers: { Authorization: 'Bearer ' + this.constantsService.access_token }
				}
			},
			autoLoad : true,
			autoSync : true,
			eventStore : {
				syncDataOnLoad : true,
				fields : [
					{ name : 'eventType' }
				],				
			},
			resourceStore : {
				syncDataOnLoad : true,
				fields : [
					{ name : 'order' }
				],		
				sorters : [{ field: 'order', ascending: false }] 
			}
		},

Thank you in advance.


Post by marcio »

Hey codevlabs,

Thanks for reaching out.

Just to confirm, do you have that custom field set in your resourceModel?

Please check this guide for more information https://bryntum.com/products/calendar/docs/guide/Calendar/data/project_data#adding-custom-fields-to-entities

Best regards,
Márcio


Post by Animal »

It does sort the resource store.

Go to https://bryntum.com/products/calendar/examples/date-resource/

Edit the code in the code editor as below:

Screenshot 2024-03-18 at 13.46.52.png
Screenshot 2024-03-18 at 13.46.52.png (131.18 KiB) Viewed 246 times

You can see the resource change order.

Do you by chance mean that you want to sort the resourceFilter's store?


Post by codevlabs »

Thanks Both.

Marcio, no I wasn't. I added two new classes but still not sorting.

Animal, Not sure tbh, I only have the default Filter events box in the Calendar.

export class CupResourceModel extends ResourceModel {   
public order: string; static override get fields() { return [ { name : 'order' } ]; } } export class CupEventModel extends EventModel {
public eventType: string; static override get fields() { return [ { name : 'eventType' } ]; } }
crudManager : {	
			validateResponse:true,		 
			transport : {
				load : {
					url : environment.baseURL + '/1/getCalendar.php?unallocYN=1',
					credentials: "omit",					
					headers: { Authorization: 'Bearer ' + this.constantsService.access_token }										
				},
				sync : {
					url : environment.baseURL + '/1/postCalendar.php',
					credentials: "omit",
					headers: { Authorization: 'Bearer ' + this.constantsService.access_token }
				}
			},
			autoLoad : true,
			autoSync : true,
			eventStore : {
				syncDataOnLoad : true,
				modelClass   : CupEventModel,					
			},
			resourceStore : {
				syncDataOnLoad : true,				
				modelClass   : CupResourceModel,					
				sorters : [{ field: 'order', ascending: false }] 
			}
		}

Post by Animal »

The resources are sorted by that sorter declaration if the resources have that field. But what are you expecting to see from that fact?

As I showed you, you would only see that in the date-resource view or resource view. Those are the only views where the resourceStore is iterated.


Post by codevlabs »

I want to sort this list. Thanks.

Attachments
Screenshot 2024-03-18 152253.png
Screenshot 2024-03-18 152253.png (43.6 KiB) Viewed 235 times

Post by Animal »

So you do want to sort the resourceFilter's store.

    sidebar : {
        resourceFilter : {
            store : {
                sorters : [...your sorters]
            }
        }
    },

Post by codevlabs »

Works Fine. Thank you Both.


Post Reply