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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Resources need to refresh on navigation

Thread ID:

Created:

Updated:

Platform:

Replies:

151032 Jan 28,2020 05:29 PM UTC Jan 29,2020 12:02 PM UTC ASP.NET MVC - EJ 2 1
loading
Tags: Schedule
Brian Perry
Asked On January 28, 2020 05:29 PM UTC

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.

Vengatesh Maniraj [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon