We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Resources need to refresh on navigation

Hi,

I am trying to build out a scheduler with resources (workers in a company) and appointments that they have. When I navigate to a new week I need to be able to remove all the current resources, make a call to our database to get workers that are active in the week navigated to and display them as the resources. I have gotten the appointment to dynamically load when navigating using a UrlAdpator and the MVC path using DataSource(d => d.Url("path")... I am trying to do something similar with the resources or be able to reload both resources and appointments on navigation.

1 Reply

VM Vengatesh Maniraj Syncfusion Team January 29, 2020 12:02 PM UTC

Hi Brian, 

Greetings from Syncfusion Support. 

We have validated the your requirement at our end and we have prepared the below sample by making call of dataBound and navigating events to achieve the requirement. To achieve your requirement, we have to provide the dates for all resources(employees) like below, 

DateTime[] nancy = new DateTime[] { 
                new DateTime(2019, 10, 8), 
                new DateTime(2019, 10, 9), 
                new DateTime(2019, 10, 10), 
                new DateTime(2019, 10, 11), 
                new DateTime(2019, 10, 12) 
            }; 
 
 
employees.Add(new ResourceDataSourceModel { text = "Nancy", id = 1, groupId = 1, color = "#df5286", dates = nancy }); 

Based on this date field, we have to filter the resources by comparing with rendered date which can be collected by making call of getCurrentViewDates method like below, 

isResourceUpdated = true; 
            var schObj = document.querySelector('.e-schedule').ej2_instances[0]; 
            var resources = []; 
            var renderedDates = schObj.getCurrentViewDates(); 
            for (var i = 0; i < empData.length; i++) { 
                for (var j = 0; j < empData[i].dates.length; j++) { 
                    for (var k = 0; k < renderedDates.length; k++) { 
                        var date = new Date(Date.parse(empData[i].dates[j])) 
                        if (date.getTime() === renderedDates[k].getTime()) { 
                            resources.push(empData[i].id); 
                            k = renderedDates.length; 
                            j = empData[i].dates.length; 
                        } 
                    } 
                } 
            } 

Once filtered the resources, we need to update the resource’s data source like below, 

let resourcePredicate; 
            for (var a = 0; a < resources.length; a++) { 
                var predicate = new ej.data.Predicate("id", "equal", resources[a]); 
                resourcePredicate = resourcePredicate ? resourcePredicate.or(predicate) : predicate; 
            } 
            let resourceQuery = resourcePredicate ? new ej.data.Query().where(resourcePredicate) : new ej.data.Query(); 
            schObj.resources[0].query = resourceQuery; 


Kindly try the above sample and revert us for further assistance. 

Regards, 
Vengatesh 


Loader.
Live Chat Icon For mobile
Up arrow icon