search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Add menu item to context menu on scheduler

Asked by Pete S
3 years ago.

I am trying to add menu items to a context menu but they are not appearing. In the Page Init I have

Dim dpmi As New MenuItem

dpmi.Action = MenuItemAction.JavaScript
dpmi.JavaScript = "showManage(column);"
dpmi.Text = "Name Required"
dpmi.ToolTip = "Tooltip required - brief description of what this does"
dpmSchedule.MenuItems.Add(dpmi)

Answer posted by Dan Letecky [DayPilot]
3 years ago.

This should work fine - I recommend checking if your Page_Init() method is being called properly. If it is, you might be overwriting the menu items somewhere else.

Comment posted by Pete S
3 years ago.

Thanks for the reply Dan.

Init is being called, everything else in it is being executed and I am not modifying the menu anywhere else. On a right click, I get the default menu for the browser and get an error in console saying that there are no menu items

The context menu is empty by default and is being populated on a certain condition. Everything else that is in that if statement is happening, so now I am at a bit of a loss.

Comment posted by Dan Letecky [DayPilot]
3 years ago.

Pete,

Thanks for the update. I'm testing it using the following setup:

aspx
<DayPilot:DayPilotScheduler 
    ID="DayPilotScheduler1" 
    runat="server" 
    ContextMenuID="DayPilotMenu2" 
    ...
    />
<DayPilot:DayPilotMenu ID="DayPilotMenu2" runat="server"></DayPilot:DayPilotMenu>
aspx.vb
Protected Sub Page_Init()
    Dim item As New MenuItem
    item.Action = MenuItemAction.JavaScript
    item.JavaScript = "showManage(column);"
    item.Text = "Name Required"
    item.ToolTip = "Tooltip required - brief description of what this does"
    DayPilotMenu2.MenuItems.Add(item)
End Sub

It seems to work fine. Would you be able to create an example that reproduces the issue?

Comment posted by Pete S
3 years ago.

This is what I have:

aspx
<DayPilot:DayPilotScheduler ID="dpsSchedule" runat="server" Width="100%" HeightSpec="Parent100Pct" ClientObjectName="dps"
    DataStartField="StartDateTime"
    DataEndField="EndDateTime"
    DataResourceField="UnitType"
    DataIdField="RecordID"
    DataTextField="Item"
    TreeEnabled="true"
    BusinessWeekends="true"
    ShowNonBusiness="true"
    BorderColor="Transparent" BorderStyle="None" BorderWidth="0px"
    CellDuration="360"
    Days="60"
    CellGroupBy="Week"
    BusinessBeginsHour="6"
    BusinessEndsHour="18"
    ContextMenuID="dpmSchedule"
    BubbleID="dpbSchedule" EventClickHandling="Bubble" ResourceBubbleID="dpbResource" EventHoverHandling="Disabled"
    OnBeforeEventRender="dpsSchedule_BeforeEventRender" OnBeforeTimeHeaderRender="dpsSchedule_BeforeTimeHeaderRender" OnBeforeCellRender="dpsSchedule_BeforeCellRender"
    DynamicEventRendering="Disabled" TimeRangeSelectedJavaScript="showEdit(start.toString(), end.toString(), column);" ViewStateMode="Disabled">
    <HeaderColumns>
        <DayPilot:RowHeaderColumn Title="Unit" Width="150" />
    </HeaderColumns>
</DayPilot:DayPilotScheduler>

<DayPilot:DayPilotBubble ID="dpbSchedule" runat="server" CssOnly="true" CssClassPrefix="bubble_default" ShowAfter="500" Animated="true" OnRenderEventBubble="dpbSchedule_RenderEventBubble"></DayPilot:DayPilotBubble>

<DayPilot:DayPilotMenu ID="dpmSchedule" runat="server" ClientObjectName="dps"></DayPilot:DayPilotMenu>
aspx.vb
If Not varSession("User") = "VIEWER" Then
    Dim dpmi As New MenuItem

    dpmi.Action = MenuItemAction.JavaScript
    dpmi.JavaScript = "showManage(column);"
    dpmi.Text = "Name Required"
    dpmi.ToolTip = "Tooltip required - brief description of what this does"
    dpmSchedule.MenuItems.Add(dpmi)

    dpsSchedule.EventRightClickHandling = Enums.EventRightClickHandlingEnum.ContextMenu


    litHelpful.Text = "2.&emsp;To edit any part of this programme, select the period on an individual unit's programme."

    dpsSchedule.TimeRangeSelectedHandling = Enums.TimeRangeSelectedHandling.JavaScript
    pEdit.Visible = True
End If

LoadResources(uID, dpsSchedule, cbEvent.Checked, cbPort.Checked, cbTask.Checked, cbUKRead.Checked, cbNATORead.Checked)
LoadScheduler(uID, dpsSchedule)

Everything is working as expected, apart from the menu item not appearing. So litHelpful is being populated, etc

Comment posted by Dan Letecky [DayPilot]
3 years ago.

OK.

1. Do you use the latest DayPilot version?
2. Are the controls inside an UpdatePanel?

Comment posted by Pete S
3 years ago.

Using Daypilot 2018.1.3644.1 and yes they are

Comment posted by Dan Letecky [DayPilot]
3 years ago.

Could you please give it a try with the latest release?
https://aspnet.daypilot.org/daypilot-pro-for-asp-net-webforms-2021-1-3792/

Comment posted by Pete S
3 years ago.

Done and no change

Comment posted by Dan Letecky [DayPilot]
3 years ago.

Could you please try to modify the following example so that it reproduces the problem?

Default.aspx
<%@ Page Language="vb" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="Scheduler_Default" Culture="en-us" %>

<%@ Register Assembly="DayPilot" Namespace="DayPilot.Web.Ui" TagPrefix="DayPilot" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>Scheduler</title>
</head>
<body>
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel runat="server">
        <ContentTemplate>
            <DayPilot:DayPilotScheduler
                ID="DayPilotScheduler1"
                runat="server"
                DataStartField="start"
                DataEndField="end"
                DataTextField="name"
                DataIdField="id"
                DataResourceField="column"
                Scale="Day"
                CellWidth="60"
                ContextMenuID="DayPilotMenu2"
                TreeEnabled="true"
                >
                <Resources>
                    <DayPilot:Resource Name="Locations" Id="GroupLocations" Expanded="true">
                        <Children>
                            <DayPilot:Resource Name="Room 1" Id="A" Expanded="False"/>
                            <DayPilot:Resource Name="Room 2" Id="B" Expanded="False"/>
                            <DayPilot:Resource Name="Room 3" Id="C" Expanded="False"/>
                            <DayPilot:Resource Name="Room 4" Id="D" Expanded="False"/>
                        </Children>
                    </DayPilot:Resource>
                </Resources>
            </DayPilot:DayPilotScheduler>

            <DayPilot:DayPilotMenu ID="DayPilotMenu2" runat="server">
            </DayPilot:DayPilotMenu>

        </ContentTemplate>
    </asp:UpdatePanel>

</form>
</body>
</html>
Default.aspx.vb
Imports System.Data
Imports DayPilot.Utils
Imports DayPilot.Web.Ui

Partial Public Class Scheduler_Default
    Inherits System.Web.UI.Page

    Private table As DataTable

    protected sub Page_Init()
        Dim item As New MenuItem
        item.Action = MenuItemAction.JavaScript
        item.JavaScript = "showManage(column);"
        item.Text = "Name Required"
        item.ToolTip = "Tooltip required - brief description of what this does"
        DayPilotMenu2.MenuItems.Add(item)
    End sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        initData()
        DayPilotScheduler1.StartDate = New Date(Date.Today.Year, 1, 1)
        DayPilotScheduler1.Days = Year.Days(Date.Today.Year)*2

        If Not IsPostBack Then
            DayPilotScheduler1.SetScrollX(Date.Today.AddDays(- 1))
            setDataSourceAndBind()
            DayPilotScheduler1.UpdateWithMessage("Welcome!")
        End If
    End Sub

    Private Sub setDataSourceAndBind()
        ' ensure that filter is loaded
        DayPilotScheduler1.DataSource = table
        DayPilotScheduler1.DataBind()
    End Sub


    ''' <summary>
    ''' Make sure a copy of the data is in the Session so users can try changes on their own copy.
    ''' </summary>
    Private Sub initData()
        table = GetData()
    End Sub

    Public Shared Function GetData() As DataTable
        Dim dt As DataTable
        dt = New DataTable()
        dt.Columns.Add("start", GetType(Date))
        dt.Columns.Add("end", GetType(Date))
        dt.Columns.Add("name", GetType(String))
        dt.Columns.Add("id", GetType(String))
        dt.Columns.Add("column", GetType(String))
        dt.Columns.Add("color", GetType(String))

        Dim dr As DataRow

        dr = dt.NewRow()
        dr("id") = 2
        dr("start") = Convert.ToDateTime("00:00")
        dr("end") = Convert.ToDateTime("00:00").AddDays(1)
        dr("name") = "Event 2"
        dr("column") = "B"
        dr("color") = "green"
        dt.Rows.Add(dr)


        dt.PrimaryKey = New DataColumn() {dt.Columns("id")}

        Return dt
    End Function
End Class
Comment posted by Pete S
3 years ago.

Ok ... after a bit of headbashing and hair removal I have figured out what was causing the problem ... as soon as I removed ClientObjectName="dps" from the menu, it all worked.

However, there is another issue, which is certainly down to my lack of knowledge. How do I pass the resource ID through on the javascript function. On the time range selected it is column, but that doesn't seem to be working for the menu item.

Comment posted by Dan Letecky [DayPilot]
3 years ago.

Great, thanks for the update. The ClientObjectName sets the name of the client-side object - if you use a value that is already used for another object (e.g. the scheduler) there will be a conflict.

You can access the event properties using "e" value which stores the DayPilot.Event object:
https://api.daypilot.org/daypilot-event-class/

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.