Customization"

From Documentation
Line 1: Line 1:
 
{{ZKCalendarEssentialsPageHeader}}
 
{{ZKCalendarEssentialsPageHeader}}
  
= Customize More Event Link =
+
= "More Event" Link =
 
If there is not enough space to show events in one day, Calendar will show a "more event" link:
 
If there is not enough space to show events in one day, Calendar will show a "more event" link:
  
Line 25: Line 25:
 
Then load the script with [[ZK_Developer%27s_Reference/Internationalization/Warning_and_Error_Messages#Defined_in_a_JS_File | land-addon.xml]]
 
Then load the script with [[ZK_Developer%27s_Reference/Internationalization/Warning_and_Error_Messages#Defined_in_a_JS_File | land-addon.xml]]
  
{{ZKCalendarEssentialsHeadingToc}}
+
 
 +
= Date Format in Captions =
 +
 
 +
You can change the date format Calendar renders in captions.
 +
 
 +
==The DateFormatter interface==
 +
 
 +
The <javadoc type="interface">org.zkoss.calendar.api.DateFormatter</javadoc> interface requires 5 methods to be implemented. These are as follows:
 +
 
 +
{| border="1"
 +
|-
 +
!Method||Usage
 +
|-
 +
||getCaptionByDayOfWeek
 +
||Returns the caption of the day of week.
 +
|-
 +
||getCaptionByTimeOfDay
 +
||Returns the caption of the time of day.
 +
|-
 +
||getCaptionByDate
 +
||Returns the caption of the date.
 +
|-
 +
||getCaptionByDateOfMonth
 +
||Returns the caption of the date of month.
 +
|-
 +
||getCaptionByPopup
 +
||Returns the caption of the popup title.
 +
|}
 +
 
 +
Each function enables us to customize the appearance of the calendar at any opportunity. Implementing an interface such as this is excellent if you require fine-grained control. If you do not require such a level of control then ZK Calendar provides you with an implementation.
 +
 
 +
 
 +
==The SimpleDateFormatter Class==
 +
 
 +
ZK Calendar provides us with the <javadoc>org.zkoss.calendar.impl.SimpleDateFormatter</javadoc> class which enables rapid development of ZK Calendar applications. The implementation is used by default within ZK Calendar. In some circumstances, you may require a more powerful implementation and therefore need to create customization.
 +
 
 +
 
 +
 
 +
==Using a Customized DateFormatter Implementation==
 +
 
 +
To make use of a customized <javadoc type="interface">org.zkoss.calendar.api.DateFormatter</javadoc> implementation we need to inform ZK Calendar that we are using our own implementation of <javadoc type="interface">org.zkoss.calendar.api.DateFormatter</javadoc>.  To do this we make use of a custom implementation we call the <mp>setDateFormatter</mp> on ZK Calendar, for example:
 +
 
 +
<source lang="java">
 +
calendar.setDateFormatter(new MyDateFormatter());
 +
</source>
 +
 
 +
<source lang='xml'>
 +
<calendars dateFormatter="foo.MyDateFormatter"/>
 +
</source>
 +
 
 +
 
  
 
{{ZKCalendarEssentialsPageFooter}}
 
{{ZKCalendarEssentialsPageFooter}}

Revision as of 07:09, 12 January 2021


Customization



"More Event" Link

If there is not enough space to show events in one day, Calendar will show a "more event" link:

MoreEventLink.png

The default text is from a javascript object.

msgcal.dayMORE = "+{0} more";
msgcal.monthMORE = "+{0} more";

To provide a different locale of text or override the text, you need to create a javascript file and load it. For example,

msgcal_zh.js

zk.afterLoad('calendar', function() {
    msgcal = {};
    msgcal.dayMORE = "+{0} 事件";
    msgcal.monthMORE = "+{0} 事件";
});//zk.afterLoad

Then load the script with land-addon.xml


Date Format in Captions

You can change the date format Calendar renders in captions.

The DateFormatter interface

The DateFormatter interface requires 5 methods to be implemented. These are as follows:

Method Usage
getCaptionByDayOfWeek Returns the caption of the day of week.
getCaptionByTimeOfDay Returns the caption of the time of day.
getCaptionByDate Returns the caption of the date.
getCaptionByDateOfMonth Returns the caption of the date of month.
getCaptionByPopup Returns the caption of the popup title.

Each function enables us to customize the appearance of the calendar at any opportunity. Implementing an interface such as this is excellent if you require fine-grained control. If you do not require such a level of control then ZK Calendar provides you with an implementation.


The SimpleDateFormatter Class

ZK Calendar provides us with the SimpleDateFormatter class which enables rapid development of ZK Calendar applications. The implementation is used by default within ZK Calendar. In some circumstances, you may require a more powerful implementation and therefore need to create customization.


Using a Customized DateFormatter Implementation

To make use of a customized DateFormatter implementation we need to inform ZK Calendar that we are using our own implementation of DateFormatter. To do this we make use of a custom implementation we call the setDateFormatter on ZK Calendar, for example:

calendar.setDateFormatter(new MyDateFormatter());
<calendars dateFormatter="foo.MyDateFormatter"/>



The example project is at Github


Last Update : 2021/01/12

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.