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

calendar to bind to custom sql on refresh

Asked by Anonymous
15 years ago.
Dan, I posted this before but never got an answer....really like the control, but this would really help. Thanks, John I am trying to get the calendar to run a new SQL databind base on the user choosing a new date. I tried to call a custom method that calls the SQL from the refresh method, but it never works. Is there a good way to pass the new start date data that comes from the javascript.dc1.refreshcallback method into a place where I can then run my custom SQL to bring back the new data for a refreshed calendar. I know that the refresh will bring a new view on the exiting set of data, but I need to bring back a whole new set of data based on some custom filters in addition to the date filter.
Comment posted by Dan Letecky
15 years ago.

The refreshCallBack() client-side function translates the parameters into a new StartDate and Days (if supplied) and send it together with your own custom data (which will contain the filter information in your case) to the server. On the server side, Refresh event is called.

So in order to update the bound data set you should handle Refresh event and rebind there. You can take a look at this documentation page (it's for DayPilotSchedulerDynamic but in DayPilotCalendar it works the same way):

www.daypilot.org/daypilotschedulerdynamic-fast-refresh-refreshcallback.html

Just a note, in DayPilot Pro 5.1 there will be a new event introduced (Command) that is a more generic replacement for refresh (it simply sends your custom data structure to the server). See also the DayPilotScheduler documentation for Command (it's already implemented for DPS):

www.daypilot.org/daypilotscheduler-commandcallback-function-universal-callback.html

Please let me know if it didn't help.

Comment posted by John
15 years ago.

The documentation for refreshcallback seem to indicated that you can only send a date or integer value. I need to send a number of other parameters. I don't suppose you would have a working example of a daypilot with some customized sql? I have spent a lot of time and am about to give up.

Thank you.

Comment posted by Dan Letecky
15 years ago.

The refreshCallBack function has three parameters:

dpc.refreshCallBack = function(date, days, data)

The third parameter is a string that can hold any custom value. In version 5.1 it will accept any object (that will be accessible as JsonData object on the server side).

In the server-side Refresh event handler, you can load the dataset using custom SQL without problems. It can look like this (a simplified example):

SqlDataAdapter da = new SqlDataAdapter("SELECT id, name, start, end FROM events WHERE filter = @filter", "connection string");
da.SelectCommand.Parameters.Add("filter", e.Data);
// ... add other parameters
DataTable dt = new DataTable();
da.Fill(dt);

DayPilotCalendar1.DataSource = dt;
DayPilotCalendar1.DataBid();

If it's still not clear, please contact me at support@daypilot.org.

Comment posted by John
15 years ago.

Dan,

I triedadding a session variable (which containsthe added data that is neededfor a custom sql call) into the refreshcallback function (see below), but itends up giving me a error in the server side event handler saying that the string isnot in theneeded datetime format.I really like the calendar, butit seems that thiscould be easier. Icould really use a working example

protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Text = "<a href=\"javascript:dpc1.refreshCallBack(new Date('" + DayPilot.Utils.JsDate.FormatDateTime(e.Day.Date) + ",," + Session["m"] + "'))\">" + e.Day.DayNumberText + "</a>";
}

I also tried putting single quotes around each of the parameters ....

protected void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
{
e.Cell.Text = "<a href=\"javascript:dpc1.refreshCallBack(new Date('" + DayPilot.Utils.JsDate.FormatDateTime(e.Day.Date) + "','','" + Session["m"] + "'))\">" + e.Day.DayNumberText + "</a>";
}

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