Hi,
Building a custom print function for my monthly calendar. Basically, I’m using JavaScript to intercept Cntl+P, presenting a modal with instructions, and providing a button that runs another JavaScript function. That function sets a value on a hidden field, gets filter preferences from another field, arrays startDate and the filter value, and then does a commandCallBack…here’s the js code:
function doPrintSetup() {
document.getElementById('hf_isPrintMode').value = '1';
const hiddenEventFilterField = document.getElementById('hidden_eventTypePrefs').value;
setTimeout(() => {
const date = dpm.startDate;
var EventFilterArray = [date, hiddenEventFilterField]
dpm.commandCallBack('print', EventFilterArray);
}, 100);
$find('modal_print').hide();
}
In BeforeEventRender (VB.NET code-behind), I have a variable that is supposed to get its value from the “hf_isPrintMode” hidden field, and I have conditionals that change EventHeight and the format of e.HTML based on the value of the variable:
Protected Sub DayPilot1_BeforeEventRender(ByVal sender As Object, ByVal e As DayPilot.Web.Ui.Events.Month.BeforeEventRenderEventArgs)
…
Dim varPrintSetup As String = If(hf_isPrintMode.Value = "", "0", "1")
…
If varPrintSetup = "1" Then
DayPilotMonth1.EventHeight = "50"
varHtmlStr = varTailNum & " [" & varAircraftSn & "]<br />" & CStr(e.DataItem("itinerary")) & "<br />" & varTimeRange & " " & varConflictPrintTag
End If
In my “DayPilot_Command(…)” sub, I have a case statement that includes the above-mentioned “print” option:
Protected Sub DayPilot1_Command(sender As Object, e As CommandEventArgs)
…
Case "print"
Dim startDate = CStr(e.Data(0))
Dim eventTypeFilterVal = CStr(e.Data(1))
DayPilotMonth1.StartDate = startDate
DayPilotMonth1.DataSource = GetData(DayPilotMonth1.VisibleStart, DayPilotMonth1.VisibleEnd, eventTypeFilterVal, "")
DayPilotMonth1.DataBind()
DayPilotMonth1.Update(DayPilot.Web.Ui.Enums.CallBackUpdateType.Full)
I know the js function is working - had a different start date set initially and calendar indexed to that date when I ran the function. However, I don’t get any change in the UI; no EventHeight change, no change in the format of my data string that is applied to e.HTML. I can also confirm that the value is being written to the hf_isPrintMode field.
In testing I discovered that the code in BeforeEventRender does work. Setting either the variable or the hidden field to a “1” results in the UI displays the modified format…it’s just not dynamically updating. I thought that is might be an issue with page life or when BeforeEventRender runs but according to Google (grain of salt there…) BeforeEventRender runs with every callback.
Any ideas? The printed result looks great (using css, etc. vs ExportAs) just need to get it to work without having to manually setting the variable value.
Thanks - Ed