Dynamically Grouping

I'm fetching events from my database using the DataManager and i'd like to group the events based on their Subject. 

How would I accomplish this? Because I'm making the groups and setting it as the resource directive data source but it's not updating. And using another DataManager for grouping seems like it only sends a get request once when the component loads, when I would need it to do it on date change like the schedule components datasource.


1 Reply

VD Vinitha Devi Murugan Syncfusion Team August 20, 2021 01:12 PM UTC

 
Greetings from Syncfusion Support. 
 
We've verified your reported query and informed you that Datamanger for resource datasource is only called on first load, as is our scheduler's default behaviour. If you want to update the resource datasource during date navigation, we recommend using the query option of datamanager in our scheduler's navigating event, as shown below. 
 
App.component.html 
<ejs-schedule #scheduleObj cssClass='schedule-group' width='100%' height='550px' [group]="group" [selectedDate]="selectedDate"  
        [eventSettings]="eventSettings" [(currentView)]="scheduleView" (popupOpen)="onPopupOpen($event)" (navigating)=”onNavigate($event)”>  
        <e-resources>  
            <e-resource field='GroupID' title='Group Name' name='Groups' [allowMultiple]='allowMultiple' [query]='querySource' [dataSource]='resourceDataManager'  
                textField='GroupName' idField='GroupID' colorField='CalendarColor'>  
            </e-resource>  
        </e-resources>  
    </ejs-schedule>  
 
App.component.ts. 
 
import { ViewEncapsulationComponentOnInitViewChild } from '@angular/core';  
import { EventSettingsModelDayServiceWeekServiceWorkWeekServiceMonthServiceAgendaServiceGroupModelScheduleComponent } from '@syncfusion/ej2-ng-schedule';  
import { DataManagerQueryPredicateUrlAdaptor } from '../../node_modules/@syncfusion/ej2-data';  
@Component({  
  selector: 'app-root',  
  templateUrl: './app.component.html',  
  styleUrls: ['./app.component.css'],  
  providers: [DayServiceWeekServiceWorkWeekServiceMonthServiceAgendaService],  
  encapsulation: ViewEncapsulation.None  
})  
export class AppComponent implements OnInit {  
  @ViewChild('scheduleObj')  
  public scheduleObjScheduleComponent;  
  public selectedDateDate = new Date(201831);  
  public resourceDataSourceObject[] = [  
    { GroupName: 'Airways 1'GroupID: 1CalendarColor: '#EA7A57' },  
    { GroupName: 'Airways 2'GroupID: 2CalendarColor: '#357cd2' },  
    { GroupName: 'Airways 3'GroupID: 3CalendarColor: '#7fa900' }  
  ];  
  
  public fieldsObject = { text: 'GroupName'value: 'GroupID' };  
  public modestring = 'Box';  
  public popHeightstring = '300px';  
  public filterPlaceholderstring = 'Select group';  
  public valuenumber[] = [1];  
  
  public scheduleView : string = "Month";  
  public resourceDataManagerDataManager = new DataManager({  
    url: 'http://localhost:54738/Home/LoadResourceData',  
    adaptor: new UrlAdaptor  
  });  
  
  public querySourceQuery = new Query().take(1);  
  private dataMangerDataManager = this.dataManger = new DataManager({  
    url: 'http://localhost:54738/Home/LoadData'// Here pass your REST WEB API load data  
    crudUrl: 'http://localhost:54738/Home/UpdateData',  
    adaptor: new UrlAdaptor  
    // headers: [{ Authorization: `Bearer ${sessionStorage.getItem("sessionTokenName")}` }]  
  });  
  
  public groupGroupModel = { resources: ['Groups'] };  
  public allowMultipleBoolean = true;  
  public eventSettingsEventSettingsModel = {  
    dataSource: this.dataManger  
  };  
    
  ngOnInit(): void {  
  
  }  
  
  public onPopupOpen(args:any){  
  
  }  
  
  public onNavigate(argsany) {  
    this.scheduleObj.resources[0].query = new Query().addParams("value",args.value.toString()).take(args.value.length);  
    this.scheduleObj.resources[0].dataSource = this.resourceDataManager;  
  }  
}  
 
Service Project: 
 
public JsonResult LoadResourceData(Filter filter) 
{ 
    string[] selectedResource = new string[10]; 
    List < ScheduleResourceData > data = new List<ScheduleResourceData>(); 
    if (filter.value != null && filter.value != "") { // This code block will execute when selecting more groups  
        selectedResource = filter.value.Split(','); 
        for (int i = 0i < selectedResource.Lengthi++) 
        { 
            var filterData = db.ScheduleResourceDatas.Where(res => res.GroupID == Convert.ToInt32(selectedResource[i])).ToList(); 
            data.Add(new ScheduleResourceData { GroupName = filterData[0].GroupNameGroupID = filterData[0].GroupIDCalendarColor = filterData[0].CalendarColor }); 
        } 
    } 
    else { // This code block will execute for the initial load  
        var filterData = db.ScheduleResourceDatas.ToList(); 
        for (int i = 0i < filterData.Counti++) 
        { 
            data.Add(new ScheduleResourceData { GroupName = filterData[0].GroupNameGroupID = filterData[0].GroupIDCalendarColor = filterData[0].CalendarColor }); 
        } 
    } 
    var resourceData = data.ToList().Take(filter.take); 
    return Json(resourceDataJsonRequestBehavior.AllowGet); 
} 
 
public class Filter { 
    public int take { getset; }  
            public string value { getset; }  
        } 
 
Also, we suggest you to refer below forum for more information. 
 
 
 
Kindly try with the above sample and get back to us if you need any further assistance. 
 
Regards, 
Vinitha 


Loader.
Up arrow icon