Deleting Past Appointments in RadScheduler
Environment
Product | RadScheduler for ASP.NET AJAX |
---|---|
Version | All |
Description
How can I delete all previously posted appointments in RadScheduler at once? I need to offer users the option to either delete a specific selected old appointment or the entire selected series of old appointments.
This KB article also answers the following questions:
- How to programmatically remove past appointments from RadScheduler?
- How to delete appointments before the current date in RadScheduler?
Solution
To delete all past appointments in RadScheduler, you can utilize a JavaScript function that iterates through all appointments and deletes those occurring before the current date.
- Add a button to your page that, when clicked, executes the following JavaScript function:
function onClick(sender, args) {
var scheduler = $find("<%= RadScheduler1.ClientID %>");
var appointments = scheduler.get_appointments();
var currentDate = new Date();
var currentDay = currentDate.getDate();
appointments.forEach((appointment) => {
var appointmentStartDate = appointment.get_start();
var startDay = appointmentStartDate.getDate();
if (startDay < currentDay) {
scheduler.deleteAppointment(appointment);
}
});
}
This script finds the RadScheduler control on the page and loops through its appointments. For each appointment, it checks if the start date is before today's date. If so, it deletes the appointment.
Suggested Workarounds
For a server-side solution in C#, you would need to retrieve all appointments from your data source, filter those that are in the past, and then delete them from both your data source and the RadScheduler. This process would depend on how you've implemented data binding for the RadScheduler and is not covered here due to the variety of possible data sources and architectures.
Notes
- The JavaScript solution provided here works directly on the client-side without additional server-side code. However, remember to handle data persistence on the server-side to ensure the changes reflect in your data source.
- For server-side deletion, ensure you rebind the RadScheduler after deleting the appointments to reflect the changes on the UI.