How to selected week in calendar in zk

自古美人都是妖i 提交于 2020-01-05 05:50:08

问题


how to selected whole week in calendar on onclick on Calendar component. Just like this image.


回答1:


You can override _markCal js function (used to mark the selected date) to style whole row and fire event to server to update selected dates, please refer to:

online demo

calendar_as_week_picker.zul

WeekPicker.java

and

related article at my blog




回答2:


For the version 7 of zk use:

<zk xmlns:w="client">
<style>
    .custom-selected-node {
        background-color: #99FF99 !important;
    }
</style>
<vlayout>
    <label value="selected dates" />
    <textbox rows="7" id="tbx" width="300px" />
</vlayout>
<calendar id="cal" use="test.custom.component.WeekPicker">
    <attribute w:name="_markCal"><![CDATA[
        function (opts) {
            // clear old custom-selected-node
            jq('.custom-selected-node').each(function () {
                jq(this).removeClass('custom-selected-node');
            });
            this.$_markCal(opts);
            if (this._view == 'day') {
                // target: current focused date (td)
                // parent: tr
                var target = jq('.z-calendar-selected')[0],
                    parent = target.parentNode,
                    node = parent.firstChild,
                    beforeCnt = 0,
                    found;
                // loop through each td
                while (node) {
                    // add selected style
                    jq(node).addClass('custom-selected-node');
                    if (node == target) {
                        found = true;
                    } else if (!found) {
                        // count nodes before target
                        beforeCnt++;
                    }
                    node = node.nextSibling;
                }
                // fire event to server
                this.fire('onCustomSelect', {bcnt: beforeCnt});
            }
        }
    ]]></attribute>
    <attribute name="onCustomSelect"><![CDATA[
        List dates = self.getSelectedDates();
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd / MM / yyyy");
        String value = "";
        for (int i = 0; i < dates.size(); i++) {
            value = value + sdf.format((Date)dates.get(i)) + "\n";
        }
        tbx.setValue(value);
    ]]></attribute>
</calendar>



来源:https://stackoverflow.com/questions/16190586/how-to-selected-week-in-calendar-in-zk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!