This is a migrated thread and some comments may be shown as answers.

[Solved] Context Menu - Custom Attributes

2 Answers 184 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
f
Top achievements
Rank 1
f asked on 23 Jan 2008, 06:32 AM
Hi,

First I would like to say that that integration with context menu looks very good.

In a Scheduler I have a custom attribute: Status.
I want ContextMenu to be shown only when Status ==1
I followed your online example and found the javasript function
appointmentContextMenu {
...
selectedAppointment = eventArgs.get_appointment();
}

So i have selectedAppointment, how can i read its custom attributes and instruct scheduler not to show the ContextMenu?

Thanks,
Florin

2 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 23 Jan 2008, 02:39 PM
Hi Florin,

Thank you for your question.

What you want to achieve could be achieved easily by getting the custom attributes on the client. Unfortunately, this is not possible at the moment, but it is in our to-do list for the next Q1 2008 release.

Meanwhile, you can use the following workaround:

aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="RadScheduler1">  
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="RadScheduler1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                        <telerik:AjaxUpdatedControl ControlID="AppointmentsList" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting> 
            </AjaxSettings> 
        </telerik:RadAjaxManager>         
 
        <telerik:RadScriptBlock runat="server" ID="RadScriptBlock1">  
            <script type="text/javascript">  
                function onAppointmentContextMenu(sender, eventArgs)  
                {  
                    var apptID = eventArgs.get_appointment().get_id();  
                    var appointmentListField = $get('<%= AppointmentsList.ClientID %>');  
                    if (appointmentListField.value)  
                    {  
                        var appointmentIDs = Sys.Serialization.JavaScriptSerializer.deserialize(appointmentListField.value);  
                        if (Array.contains(appointmentIDs, apptID))  
                        {                            
                           showMenu(event);  
                        }  
                    }  
                }  
                function showMenu(e)  
                {  
                    var contextMenu = $find("<%= RadContextMenu1.ClientID %>");  
                      
                    if ((!e.relatedTarget) || (!Telerik.Web.DomUtility.isDescendantOrSelf(contextMenu.get_element(), e.relatedTarget)))  
                    {  
                        contextMenu.show(e);  
                    }  
                      
                    Telerik.Web.DomElement.cancelRawEvent(e);  
                }  
 
                  
            </script> 
        </telerik:RadScriptBlock> 
          
        <asp:HiddenField runat="server" ID="AppointmentsList" /> 
          
        <telerik:RadScheduler ID="RadScheduler1" runat="server" DataEndField="End" OnClientAppointmentContextMenu="onAppointmentContextMenu" ... > 
            

code-behind:
protected void RadScheduler1_DataBound(object sender, EventArgs e)  
    {  
        List<int> appointmentIDs = new List<int>();  
        foreach (Appointment appt in RadScheduler1.Appointments)  
        {  
            if (appt.Attributes["HasContextMenu"] != "" &&  
                appt.Attributes["HasContextMenu"] != null)  
            {  
                appointmentIDs.Add((int) appt.ID);  
            }  
        }  
 
        JavaScriptSerializer serializer = new JavaScriptSerializer();  
        AppointmentsList.Value = serializer.Serialize(appointmentIDs);  
    } 

What the above code does is to store the IDs of the appointments whose custom attribute "HasContextMenu" is not an empty string (appointments which should have context menu) in a hidden field. Then, on the client we parse the serilalized value, check which appointment should have a context menu and call the showMenu(e) function when needed.

I hope this helps.



Best wishes,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
f
Top achievements
Rank 1
answered on 23 Jan 2008, 07:34 PM
Hi Peter,

Thanks a lot, it solved the issue.

Cheers,
Florin
Tags
Scheduler
Asked by
f
Top achievements
Rank 1
Answers by
Peter
Telerik team
f
Top achievements
Rank 1
Share this question
or