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

How to execute client side JavaScript function whilst server processing request after user clicks on event blocks? [DayPilot Monthly Event Calendar]

Asked by Anonymous
24 days ago.

Hi,

Just wondering is it possible to fire JS code whilst a user request (i.e. "EventClickHandling='PostBack' ", "TimeRangeSelected='PostBack' ") is being processed by the backend server?

Sometimes when the server deals with function handlers, OnEventClick(), OnTimeRangeSelected() is takes a while to deal with the request. So is there any way I can execute a JS function (that displays a custom loading spinner with a please wait caption that informs the user the loading state of the application) before the response is made by the server?

If I can get any thoughts into this, that'd be great.
Many Thanks.

Answer posted by Dan Letecky [DayPilot]
24 days ago.

You can use EventClickHandling='PostBack' and invoke the PostBack manually using eventClickPostBack() from EventClickJavaScript, after executing your code:

https://api.daypilot.org/daypilot-scheduler-eventclickpostback/

EventClickJavaScript="yourMethod(); dp.eventClickPostBack(e);"

Similar methods exist for all other events as well.

Comment posted by Anonymous
17 days ago.

When I try clicking an event on my DayPilotMonth calendar, the following code executes the server-side function handler, `dpm_EventClick`, but does not fire the client-side function, `showLoader()` in order to display an animated loading spinner via modal window whilst the server request is happening. It seems like it is not invoking the PostBack manually from ` EventClickJavaScript="..." `

<DayPilot:DayPilotMonth ID="dpm" runat="server" ClientObjectName="dp"
    DataSourceID="sqlDataSource" DataTextField="Text" ="Value"
    DataStartField="Start" DataEndField="End"
    EventClickHandling="PostBack"
    OnEventClick="dpMonth_EventClick"
    EventClickJavaScript="showLoader(); dp.eventClickPostBack(e);" 
/>

<script type="text/javascript">
	function showLoader() {
		$('myModal_Loader').modal('show');	
	}
</script>
Comment posted by Dan Letecky [DayPilot]
17 days ago.

I'm sorry, there is a typo in my answer - the EventClickHandling property needs to be set to "JavaScript", not "PostBack":

<DayPilot:DayPilotMonth ID="dpm" runat="server" ClientObjectName="dp"
DataSourceID="sqlDataSource" DataTextField="Text" ="Value"
DataStartField="Start" DataEndField="End"
EventClickHandling="JavaScript"
OnEventClick="dpMonth_EventClick"
EventClickJavaScript="showLoader(); dp.eventClickPostBack(e);"
/>
Comment posted by Anonymous
14 days ago.

Thanks Dan, the loading spinner are showing in JS as expected before response is posted from the server whenever I select a time range or click on an existing event block. Thanks again.

Is it possible to show a loading spinner when I delete an event via `OnEventMenuClick` handler?
The following code does show the loading spinner, however the PostBack handler doesn't get fired by the server - so it's just displaying the loader infinitely.

<DayPilot:DayPilotMonth ID="dp" runat="server" ClientObjectName="dp"
             OnEventMenuClick="dp_Cal_EventMenuClick" 
/>

<DayPilot:DayPilotMenu ID="dpm" runat="server" ClientObjectName="dpm" >
      <DayPilot:MenuItem Text="Delete" Command="Delete" Action="PostBack" 
                                JavaScript="showLoader();  dpm.eventMenuClickPostBack(e, command)"  />
</DayPilot:DayPilotMenu>
Comment posted by Dan Letecky [DayPilot]
14 days ago.

The menu click mechanism is the same. You just need to change the Action to "JavaScript" - then it will execute the JavaScript code from the JavaScript property:

<DayPilot:MenuItem Text="Delete" Command="Delete" Action="JavaScript"
JavaScript="showLoader(); dpm.eventMenuClickPostBack(e, command)" />
Comment posted by Anonymous
14 days ago.

So I changed the `Action` attribute to "JavaScript", it seems like the `.eventMenuClickPostBack()` is not getting recognised...

This is what I got on the console log:
`Uncaught TypeError: dpm.eventMenuClickPostBack is not a function`

Comment posted by Dan Letecky [DayPilot]
14 days ago.

You need to change it to dp.eventMenuClickPostBack() - this is a method of <DayPilot:DayPilotMonth>, not of the context menu.

https://api.daypilot.org/daypilot-month-eventmenuclickpostback/

New Reply
This reply is
Your name (optional):