extjs的日期时间空间datetimefiled

/**
 * 此控件支持Ext3.2及以上版本
 * 用法与Ext.form.DateField一样
 * 例如:var startDt = new Ext.ux.DateTimeField({fieldLabel:‘开始时间‘,name:‘startTm‘});
 */
Ext.ux.DateTimeField = Ext.extend(Ext.form.DateField, {
	width:145,
	format:‘Y-m-d H:i:s‘,
	onTriggerClick : function(){
        if(this.disabled){
            return;
        }
        if(this.menu == null){
            this.menu = new Ext.ux.DateTimeMenu({
                hideOnClick: false,
                focusOnSelect: false
            });
        }
        this.onFocus();
        Ext.apply(this.menu.picker,  {
            minDate : this.minValue,
            maxDate : this.maxValue,
            disabledDatesRE : this.disabledDatesRE,
            disabledDatesText : this.disabledDatesText,
            disabledDays : this.disabledDays,
            disabledDaysText : this.disabledDaysText,
            format : this.format,
            showToday : this.showToday,
            minText : String.format(this.minText, this.formatDate(this.minValue)),
            maxText : String.format(this.maxText, this.formatDate(this.maxValue))
        });
        this.menu.picker.setValue(this.getValue() || new Date());
        this.menu.show(this.el, "tl-bl?");
        this.menuEvents(‘on‘);
    },
    getErrors: function(value) {
        var errors = Ext.form.DateField.superclass.getErrors.apply(this, arguments);

        value = this.formatDate(value || this.processValue(this.getRawValue()));

        if (value.length < 1) { // if it‘s blank and textfield didn‘t flag it then it‘s valid
             return errors;
        }

        var svalue = value;
        value = this.parseDate(value);
        if (!value) {
            errors.push(String.format(this.invalidText, svalue, this.format));
            return errors;
        }

        var time = value.getTime();
        if (this.minValue && time < this.minValue.getTime()) {
            errors.push(String.format(this.minText, this.formatDate(this.minValue)));
        }

        if (this.maxValue && time > this.maxValue.getTime()) {
            errors.push(String.format(this.maxText, this.formatDate(this.maxValue)));
        }

        if (this.disabledDays) {
            var day = value.getDay();

            for(var i = 0; i < this.disabledDays.length; i++) {
                if (day === this.disabledDays[i]) {
                    errors.push(this.disabledDaysText);
                    break;
                }
            }
        }

        var fvalue = this.formatDate(value);
        if (this.disabledDatesRE && this.disabledDatesRE.test(fvalue)) {
            errors.push(String.format(this.disabledDatesText, fvalue));
        }

        return errors;
    }
});

Ext.ux.DateTimeMenu = Ext.extend(Ext.menu.DateMenu, {
	initComponent : function(){
        this.on(‘beforeshow‘, this.onBeforeShow, this);
        if(this.strict = (Ext.isIE7 && Ext.isStrict)){
            this.on(‘show‘, this.onShow, this, {single: true, delay: 20});
        }
        Ext.apply(this, {
            plain: true,
            showSeparator: false,
            items: this.picker = new Ext.ux.DateTimePicker(Ext.applyIf({
                internalRender: this.strict || !Ext.isIE,
                ctCls: ‘x-menu-date-item‘,
                id: this.pickerId,
                showToday:true
            }, this.initialConfig))
        });
        this.picker.purgeListeners();
        Ext.menu.DateMenu.superclass.initComponent.call(this);

        /**
         * @event select
         * Fires when a date is selected from the {@link #picker Ext.DatePicker}
         * @param {DatePicker} picker The {@link #picker Ext.DatePicker}
         * @param {Date} date The selected date
         */
        this.relayEvents(this.picker, [‘select‘]);
        this.on(‘show‘, this.picker.focus, this.picker);
        this.on(‘select‘, this.menuHide, this);
        if(this.handler){
            this.on(‘select‘, this.handler, this.scope || this);
        }
    },
    onRender:function(){
    	Ext.ux.DateTimeMenu.superclass.onRender.apply(this, arguments);
    	if (Ext.isIE) {
    		this.el.dom.style.height = "227px";
    	}
    }
});

Ext.ux.DateTimePicker = Ext.extend(Ext.DatePicker, {
	setValue : function(value){
        this.value = value;
        this.update(this.value);
    },
    initComponent : function(){
        Ext.DatePicker.superclass.initComponent.call(this);

        this.hourEl = document.createElement("SELECT");
				this.minuteEl = document.createElement("SELECT");
				this.secondEl = document.createElement("SELECT");

				this.hourEl.style.visibility="visible";
				this.minuteEl.style.visibility="visible";
				this.secondEl.style.visibility="visible";

        this.value = this.value ? this.value : new Date();

        this.addEvents(
            /**
             * @event select
             * Fires when a date is selected
             * @param {DatePicker} this DatePicker
             * @param {Date} date The selected date
             */
            ‘select‘
        );

        if(this.handler){
            this.on(‘select‘, this.handler,  this.scope || this);
        }

        this.initDisabledDays();
    },
    handleDateClick : function(e, t){
        e.stopEvent();
        if(!this.disabled && t.dateValue && !Ext.fly(t.parentNode).hasClass(‘x-date-disabled‘)){
            this.cancelFocus = this.focusOnSelect === false;
            var dt = new Date(t.dateValue);
			dt.setHours(this.hourEl.options[this.hourEl.selectedIndex].value);
			dt.setMinutes(this.minuteEl.options[this.minuteEl.selectedIndex].value);
			dt.setSeconds(this.secondEl.options[this.secondEl.selectedIndex].value);
            this.setValue(dt);
            delete this.cancelFocus;
            this.fireEvent(‘select‘, this, this.value);
        }
    },
    selectToday : function(){
		this.value.setHours(this.hourEl.options[this.hourEl.selectedIndex].value);
		this.value.setMinutes(this.minuteEl.options[this.minuteEl.selectedIndex].value);
		this.value.setSeconds(this.secondEl.options[this.secondEl.selectedIndex].value);
		this.fireEvent(‘select‘, this, this.value);
    },
    update : function(date, forceRefresh){
        if(this.rendered){
    		if (this.el && this.activeDate) {
				this.hourEl.options[date.getHours()].selected=true;
				this.minuteEl.options[date.getMinutes()].selected=true;
				this.secondEl.options[date.getSeconds()].selected=true;
			}

            var vd = this.activeDate, vis = this.isVisible();
            this.activeDate = date;
            if(!forceRefresh && vd && this.el){
                var t = date.clearTime(true).getTime();
                if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
                    this.cells.removeClass(‘x-date-selected‘);
                    this.cells.each(function(c){
                       if(c.dom.firstChild.dateValue == t){
                           c.addClass(‘x-date-selected‘);
                           if(vis && !this.cancelFocus){
                               Ext.fly(c.dom.firstChild).focus(50);
                           }
                           return false;
                       }
                    }, this);
                    return;
                }
            }
            var days = date.getDaysInMonth(),
                firstOfMonth = date.getFirstDateOfMonth(),
                startingPos = firstOfMonth.getDay()-this.startDay;

            if(startingPos < 0){
                startingPos += 7;
            }
            days += startingPos;

            var pm = date.add(‘mo‘, -1),
                prevStart = pm.getDaysInMonth()-startingPos,
                cells = this.cells.elements,
                textEls = this.textNodes,
                // convert everything to numbers so it‘s fast
                d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart, this.initHour)),
                today = new Date().clearTime().getTime(),
                sel = date.clearTime(true).getTime(),
                min = this.minDate ? this.minDate : Number.NEGATIVE_INFINITY,
                max = this.maxDate ? this.maxDate : Number.POSITIVE_INFINITY,
                ddMatch = this.disabledDatesRE,
                ddText = this.disabledDatesText,
                ddays = this.disabledDays ? this.disabledDays.join(‘‘) : false,
                ddaysText = this.disabledDaysText,
                format = this.format;

            if(this.showToday){
                var td = new Date(),
                    disable = ((ddMatch && format && ddMatch.test(td.dateFormat(format))) ||
                    (ddays && ddays.indexOf(td.getDay()) != -1));

                if(!this.disabled){
                    this.todayBtn.setDisabled(disable);
                    this.todayKeyListener[disable ? ‘disable‘ : ‘enable‘]();
                }
            }

            var setCellClass = function(cal, cell){
                cell.title = ‘‘;
                var t = d.clearTime().getTime();
                cell.firstChild.dateValue = t;
                if(t == today){
                    cell.className += ‘ x-date-today‘;
                    cell.title = cal.todayText;
                }
                if(t == sel){
                    cell.className += ‘ x-date-selected‘;
                    if(vis){
                        Ext.fly(cell.firstChild).focus(50);
                    }
                }
                // disabling
                if(t < min) {
                    cell.className = ‘ x-date-disabled‘;
                    cell.title = cal.minText;
                    return;
                }
                if(t > max) {
                    cell.className = ‘ x-date-disabled‘;
                    cell.title = cal.maxText;
                    return;
                }
                if(ddays){
                    if(ddays.indexOf(d.getDay()) != -1){
                        cell.title = ddaysText;
                        cell.className = ‘ x-date-disabled‘;
                    }
                }
                if(ddMatch && format){
                    var fvalue = d.dateFormat(format);
                    if(ddMatch.test(fvalue)){
                        cell.title = ddText.replace(‘%0‘, fvalue);
                        cell.className = ‘ x-date-disabled‘;
                    }
                }
            };

            var i = 0;
            for(; i < startingPos; i++) {
                textEls[i].innerHTML = (++prevStart);
                d.setDate(d.getDate()+1);
                cells[i].className = ‘x-date-prevday‘;
                setCellClass(this, cells[i]);
            }
            for(; i < days; i++){
                var intDay = i - startingPos + 1;
                textEls[i].innerHTML = (intDay);
                d.setDate(d.getDate()+1);
                cells[i].className = ‘x-date-active‘;
                setCellClass(this, cells[i]);
            }
            var extraDays = 0;
            for(; i < 42; i++) {
                 textEls[i].innerHTML = (++extraDays);
                 d.setDate(d.getDate()+1);
                 cells[i].className = ‘x-date-nextday‘;
                 setCellClass(this, cells[i]);
            }

            this.mbtn.setText(this.monthNames[date.getMonth()] + ‘ ‘ + date.getFullYear());

            if(!this.internalRender){
                var main = this.el.dom.firstChild,
                    w = main.offsetWidth;
                this.el.setWidth(w + this.el.getBorderWidth(‘lr‘));
                Ext.fly(main).setWidth(w);
                this.internalRender = true;
                // opera does not respect the auto grow header center column
                // then, after it gets a width opera refuses to recalculate
                // without a second pass
                if(Ext.isOpera && !this.secondPass){
                    main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + ‘px‘;
                    this.secondPass = true;
                    this.update.defer(10, this, [date]);
                }
            }
        }
    },
	onRender:function(container, position){
		Ext.ux.DateTimePicker.superclass.onRender.apply(this, arguments);
		//重置按钮文本
		this.todayBtn.setText(this.okText);
		this.todayBtn.setTooltip(‘‘);

		//设置时、分、秒下拉框
		var row = document.createElement(‘tr‘);
		var td = document.createElement(‘td‘);
		td.colSpan="7";
		td.align="center";
		var hmTb = document.createElement(‘table‘);
		var hmBody = document.createElement(‘tbody‘);
		var hmTr = document.createElement(‘tr‘);

		var hmHoursTd = document.createElement(‘td‘);
		hmHoursTd.className = "x-date-hour";

		hmHoursTd.appendChild(this.hourEl);
		for(var i=0;i<24;i++){
			var houroption = document.createElement("OPTION");
			houroption.value=i;
			houroption.text=i;
			this.hourEl.options.add(houroption);
		}
		this.hourEl.options[this.value.getHours()].selected=true;

		hmTr.appendChild(hmHoursTd);

		var hmSepTd = document.createElement(‘td‘);
		hmSepTd.appendChild(document.createTextNode(":"));
		hmTr.appendChild(hmSepTd);

		var hmMinuteTd = document.createElement(‘td‘);
		hmMinuteTd.className = "x-date-minute";
		hmMinuteTd.appendChild(this.minuteEl);
		for(var i=0;i<60;i++){
			var minuteOption = document.createElement("OPTION");
			minuteOption.value=i;
			minuteOption.text=i;
			this.minuteEl.options.add(minuteOption);
		}
		this.minuteEl.options[this.value.getMinutes()].selected=true;

		hmTr.appendChild(hmMinuteTd);

		hmSepTd = document.createElement(‘td‘);
		hmSepTd.appendChild(document.createTextNode(":"));
		hmTr.appendChild(hmSepTd);

		var hmSecondTd = document.createElement(‘td‘);
		hmSecondTd.className = "x-date-second";
		hmSecondTd.appendChild(this.secondEl);
		for(var i=0;i<60;i++){
			var minuteOption = document.createElement("OPTION");
			minuteOption.value=i;
			minuteOption.text=i;
			this.secondEl.options.add(minuteOption);
		}
		this.secondEl.options[this.value.getSeconds()].selected=true;

		hmTr.appendChild(hmSecondTd);

		hmBody.appendChild(hmTr);
		hmTb.appendChild(hmBody);

		td.appendChild(hmTb);
		row.appendChild(td);

		//添加至确定按钮之前
		this.el.dom.firstChild.firstChild.insertBefore(row, this.el.dom.firstChild.firstChild.lastChild);
	}
});

Ext.reg(‘datetimefield‘, Ext.ux.DateTimeField);

网上找的,怕以后用就存下来,在extjs3中可以用,还有少许问题,但不影响使用

var datetime1 = new Ext.ux.DateTimeField({
id : ‘start_time_field‘,
name : ‘startTime‘,
xtype : ‘datetimefield‘,
// format : ‘Y-m-d‘,
width : 150,
editable : true
});

时间: 2024-10-18 06:23:25

extjs的日期时间空间datetimefiled的相关文章

layDate日期时间空间

真心不错,果断收藏了. 1.示例与效果 2.更多示例与皮肤

Extjs 5 可选择日期+时间的组件DateTimeField

我们都知道ExtJs有日期组件DateField,但直到ExtJs 5.0版本该日期组件也只能选择日期,不能选择时间(具体到时.分.秒),而实际工作中又常常会有需要日期和时间同时选择的需求,我们只能自己扩展了,网上也有一些扩展好的现成组件,要么是早期版本的,ExtJs5.0版本的无法用,要么就是测试不充分,代码拿过来也用不了.于是笔者就只能自己动手了.先来看一下完成后的效果图: 先说一下思路: 我们需要如上图这样的组件,首先我们得有一个能够设置时.分.秒的组件,我们取名TimePickerFie

包装类、Date类、SimpleDateFormat类(基本数据类型&lt;--&gt;String&lt;--&gt;日期/时间)

基本数据类型-->String "+"字符串连接符 基本数据类型<--String 基本数据类型 包装类 String-->xxx xxx parseXxx(String s) byte  Byte byte parseByte(String s) short   Short short parseShort(String s) int  Integer int parseInt(String s) long Long long parseLong(String s)

Extjs DateTime 日期时间选择控件 (非点击日期强制选择) 支持4.0以上

Extjs的日期控件,仅仅能支持到日期选择,对时间的选择并不完好.而网上下载的控件,都是基于Ext.form.dateField 开发.在选中日期后自己主动选择,并隐藏此选择窗体. 在经过一番改造后,最终做好了一个带确认button的时间选择控件.截图例如以下 详细代码在附件里.  要想正常使用,还须要加一段css样式: .x-datepicker-sel { border-color: rgb(224, 162, 162); border-style: solid; border-width:

ORACLE日期时间函数

ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02   13:45:25为例)           Year:              yy two digits 两位年                显示值:07        yyy three digits 三位年                显示值:007        yyyy four digits 四位年                显示值:2007                    Month

UIDatePicker 日期/时间选取器(滚轮)—IOS开发

UIDatePicker 是一个控制器类,封装了 UIPickerView,但是他是UIControl的子类,专门用于接受日期.时间和持续时长的输入.日期选取器的各列会按照指定的风格进行自动配置,这样就让开发者不必关心如何配置表盘这样的底层操作.你也可以对其进行定制,令其使用任何范围的日期. UIDatePicker 依赖于 NSDate 类,这个类是cocoa 基础的一员,以前用于桌面系统.本文中仅需用到 initWithString 来创建NSDate 所以NSDate 留待专题讲解,你只需

UIDatePicker日期/时间选取器的用法 与+NSDate和NSString的相互转换

 UIDatePicker日期/时间选取器 UIDatePicker 是一个控制器类,封装了 UIPickerView,但是他是UIControl的子类,专门用于接受日期.时间和持续时长的输入.日期选取器的各列会按照指定的风格进行自动配置,这样就让开发者不必关心如何配置表盘这样的底层操作.你也可以对其进行定制,令其使用任何范围的日期. UIDatePicker 依赖于 NSDate 类,这个类是cocoa 基础的一员,以前用于桌面系统.本文中仅需用到 initWithString 来创建NSDa

UIDatepicker 日期时间选取器(滚动)

UIDatePicker 是一个控制器类,封装了 UIPickerView,但是他是UIControl的子类,专门用于接受日期.时间和持续时长的输入.日期选取器的各列会按照指定的风格进行自动配置,这样就让开发者不必关心如何配置表盘这样的底层操作.你也可以对其进行定制,令其使用任何范围的日期. UIDatePicker 依赖于 NSDate 类,这个类是cocoa 基础的一员,以前用于桌面系统.本文中仅需用到 initWithString 来创建NSDate 所以NSDate 留待专题讲解,你只需

【转】ORACLE日期时间 等函数大全

转自:ORACLE日期时间函数大全 ORACLE日期时间函数大全 TO_DATE格式(以时间:2007-11-02   13:45:25为例)           Year:              yy two digits 两位年                显示值:07        yyy three digits 三位年                显示值:007        yyyy four digits 四位年                显示值:2007