- Home
- Forum
- ASP.NET Core - EJ 2
- add resources dynamically
add resources dynamically
Hello,
I am trying to add resources grouped by services dynamically
scheduleObj.addResource(resourceData[0], 'Resources', id - 1);
i get duplicate resource under every service but only event related to that resource and service is displayed
how do I fix this , i want to display only one resource without duplicates .
Thank you
any idea what's can cause this ?
Hi Lamia,
We suspect that you may have made a mistake in
obtaining the ID value from the checkbox in your sample code, which could cause
issues in the removeResource
method when the checkbox is unchecked. If our assumption is correct, you
need to correct it as demonstrated in the code snippet below, and it will
resolve your issue. Try the shared sample. If you are still facing issues,
kindly provide the following information:
- Whether we have missed anything in the prepared sample?
- Can you please share all the code snippets related to the Scheduler?
- If any console errors occur, kindly share them.
- Additionally, sharing an issue-reproducing video demo or providing a simplified sample that replicates the issue would greatly help us understand and resolve the problem.
[index.cshtml]
|
<script type="text/javascript"> function onChange(args) { var calendarCollections = [ { CalendarName: 'Company', CalendarId: 1, CalendarColor: '#ff7f50' }, { CalendarName: 'Birthday', CalendarId: 2, CalendarColor: '#AF27CD' }, { CalendarName: 'Holiday', CalendarId: 3, CalendarColor: '#808000' } ]; var scheduleObj = document.getElementById('schedule').ej2_instances[0]; var id = parseInt((args.event.currentTarget).querySelector('input').getAttribute('value'), 10); var resourceData = calendarCollections.filter(function (calendar) { return calendar.CalendarId === id; }); if (args.checked) { scheduleObj.addResource(resourceData[0], 'Calendars', id - 1); } else { scheduleObj.removeResource(id, 'Calendars'); } } </script> |
Regards,
Venkatesh
Attachment: ej2corescheduler_50dc5bc.zip
hello
thank you for your response but it doesn't solve the probleme
I am adding the resource on document load cause i want to display only one resource at first with this code
if (selectedResources == resourceData[0].IdContrat) {
scheduleObj.addResource(resourceData[0], 'Resources', idContratVal - 1);
}
if (selectedResources != resourceData[0].IdContrat) {
scheduleObj.removeResource(resourceData[0], 'Resources');
}
and the result is this :
any thoughts please ?
Lamia,
We have checked the codes you shared and found that you have incorrectly passed parameters in the removeResource method. The method requires the resource ID and name as parameters, but you have directly passed the resource, which may cause issues. Kindly update the parameters as required.
Furthermore, we need clarification regarding the resource you want to add or remove. Do you need to remove the parent resource or its child resource dynamically? Additionally, if you only need to render a single resource during the initial load, we suggest rendering it directly and handling the dynamic add/remove case later.
If you are still experiencing issues, provide us with the following information:
- Share all the schedule-related code snippets along with the details of resource grouping.
- Provide a simple sample that replicates the issue or replicate the issue in the last shared sample.
- Give us more details about your requirements or the use case scenario.
Regards,
Venkatesh
Thank you for your response , could you please share an example of how to render a single resource during the initial load
Lamia,
Demo: https://ej2.syncfusion.com/aspnetcore/Schedule/AddRemoveResources#/bootstrap5
UG: https://ej2.syncfusion.com/aspnetcore/documentation/schedule/resources?cs-save-lang=1&cs-lang=razor#dynamically-add-and-remove-resources
We have created a sample based on your
requirements. In this sample, the Company resource is initially rendered, and
you can dynamically add or remove additional resources by checking or
unchecking the corresponding checkboxes as needed. Try the shared sample. Refer
to the shared UG and Demo for more details.
Attachment: AddRemoveResources_a46ace95.zip
- 7 Replies
- 2 Participants
-
LA lamia
- Jul 11, 2023 06:36 AM UTC
- Jul 20, 2023 10:08 AM UTC