`
dowhathowtodo
  • 浏览: 778715 次
文章分类
社区版块
存档分类
最新评论

Extjs dataField 扩展时分秒

 
阅读更多

Ext.ns('Ext.ux.form');
Ext.ux.form.TimePickerField=function(config) {
Ext.ux.form.TimePickerField.superclass.constructor.call(this, config);
}
Ext.extend(Ext.ux.form.TimePickerField, Ext.form.Field, {
defaultAutoCreate: {tag: 'div'},
cls: 'x-form-timepickerfield',
hoursSpinner: null,
minutesSpinner: null,
secondsSpinner: null,
spinnerCfg: {
width: 40
},
spinnerFixBoundries: function(value){
if(value<this.field.minValue) {
value=this.field.maxValue;
}
if(value>this.field.maxValue) {
value=this.field.minValue;
}
return this.fixPrecision(value);
},
onRender: function(ct, position){
Ext.ux.form.TimePickerField.superclass.onRender.call(this, ct, position);
this.rendered=false;
this.date=new Date();
var values={};
if(this.value) {
values=this._valueSplit(this.value);
this.date.setHours(values.h);
this.date.setMinutes(values.m);
this.date.setSeconds(values.s);
delete this.value;
}
else {
values={h:this.date.getHours(), m:this.date.getMinutes(), s:this.date.getSeconds()};
}
var spinnerWrap=Ext.DomHelper.append(this.el, {tag: 'div'});
var cfg=Ext.apply({}, this.spinnerCfg, {
renderTo: spinnerWrap,
readOnly: this.readOnly,
disabled: this.disabled,
listeners: {
spin: {
fn: this.onSpinnerChange,
scope: this
},
valid: {
fn: this.onSpinnerChange,
scope: this
},
afterrender: {
fn: function(spinner) {
spinner.wrap.applyStyles('float: left');
},
single: true
}
}
});
this.hoursSpinner=new Ext.ux.form.SpinnerField(
Ext.apply({}, cfg, {
minValue: 0,
maxValue: 23,
cls: 'first',
value: values.h
})
);
this.minutesSpinner=new Ext.ux.form.SpinnerField(
Ext.apply({}, cfg, {
minValue: 0,
maxValue: 59,
value: values.m
})
);
this.secondsSpinner=new Ext.ux.form.SpinnerField(
Ext.apply({}, cfg, {
minValue: 0,
maxValue: 59,
value: values.s
})
);
Ext.DomHelper.append(spinnerWrap, {tag: 'div', cls: 'x-form-clear-left'});
this.rendered=true;
},
_valueSplit: function(v) {
var split=v.split(':');
return {
h: split.length>0 ? split[0] : 0,
m: split.length>1 ? split[1] : 0,
s: split.length>2 ? split[2] : 0
};
},
onSpinnerChange: function() {
if(!this.rendered) {
return;
}
this.fireEvent('change', this, this.getRawValue());
},
disable: function() {
Ext.ux.form.TimePickerField.superclass.disable.call(this);
this.hoursSpinner.disable();
this.minutesSpinner.disable();
this.secondsSpinner.disable();
},
enable: function() {
Ext.ux.form.TimePickerField.superclass.enable.call(this);
this.hoursSpinner.enable();
this.minutesSpinner.enable();
this.secondsSpinner.enable();
},
setReadOnly: function(r) {
Ext.ux.form.TimePickerField.superclass.setReadOnly.call(this, r);
this.hoursSpinner.setReadOnly(r);
this.minutesSpinner.setReadOnly(r);
this.secondsSpinner.setReadOnly(r);
},
clearInvalid: function() {
Ext.ux.form.TimePickerField.superclass.clearInvalid.call(this);
this.hoursSpinner.clearInvalid();
this.minutesSpinner.clearInvalid();
this.secondsSpinner.clearInvalid();
},
getRawValue: function() {
if(!this.hoursSpinner){
this.date=new Date();
return {h:this.date.getHours(), m:this.date.getMinutes(), s:this.date.getSeconds()};
}else{
return {
h: this.hoursSpinner.getValue(),
m: this.minutesSpinner.getValue(),
s: this.secondsSpinner.getValue()
};
}
},
setRawValue: function(v) {
this.hoursSpinner.setValue(v.h);
this.minutesSpinner.setValue(v.m);
this.secondsSpinner.setValue(v.s);
},
isValid: function(preventMark) {
return this.hoursSpinner.isValid(preventMark) &&
this.minutesSpinner.isValid(preventMark) &&
this.secondsSpinner.isValid(preventMark);
},
validate: function() {
return this.hoursSpinner.validate() &&
this.minutesSpinner.validate() &&
this.secondsSpinner.validate();
},
getValue: function() {
var v=this.getRawValue();
return String.leftPad(v.h, 2, '0')+':'+
String.leftPad(v.m, 2, '0')+':'+
String.leftPad(v.s, 2, '0');
},
setValue: function(value) {
if(!this.rendered) {
this.value=value;
return;
}
value=this._valueSplit(value);
this.setRawValue(value);
this.validate();
}
});

Ext.form.TimePickerField=Ext.ux.form.TimePickerField;
Ext.reg('timepickerfield', Ext.form.TimePickerField);
Ext.ns('Ext.ux.form');
Ext.DateTimePicker = Ext.extend(Ext.DatePicker, {
timeFormat:'g:i:s A',
timeLabel:'时间',
timeWidth:100,
initComponent:function() {
Ext.DateTimePicker.superclass.initComponent.call(this);
this.id = Ext.id();
},
onRender: function(container,position){
Ext.DateTimePicker.superclass.onRender.apply(this,arguments);
var table = Ext.get(Ext.DomQuery.selectNode('table tbody',container.dom));
var tfEl = Ext.DomHelper.insertBefore(table.last(),{tag:'tr',
children:[{tag:'td',cls:'x-date-bottom',html:this.timeLabel,style:'width:30;'},{tag:'td',cls:'x-date-bottom ux-timefield', colspan:'2'}]},true);
this.tf.render(table.child('td.ux-timefield'));
var p=this.getEl().parent('div.x-layer');
if (p){
p.setStyle("height",p.getHeight()+31);
}
},
setValue : function(value){
var old = this.value;
if (!this.tf){
this.tf = new Ext.ux.form.TimePickerField();
this.tf.ownerCt = this;
}
this.value = this.getDateTime(value);
},
getDateTime: function(value){
if (this.tf){
var dt = new Date();
var timeval = this.tf.getValue();
value = Date.parseDate(value.format(this.dateFormat) + ' ' +this.tf.getValue(),this.format);
}
return value;
},
selectToday : function(){
if(this.todayBtn && !this.todayBtn.disabled){
this.value=this.getDateTime(new Date());
this.fireEvent("select", this, this.value);
}
}
});
Ext.reg('datetimepickerfield', Ext.DateTimePicker);
if (parseInt(Ext.version.substr(0, 1), 10) > 2) {
Ext.menu.DateTimeItem = Ext.DateTimePicker;
Ext.override(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.DatePicker(Ext.apply({
internalRender: this.strict || !Ext.isIE,
ctCls: 'x-menu-date-item'
}, this.initialConfig))
});
Ext.menu.DateMenu.superclass.initComponent.call(this);
this.relayEvents(this.picker, ["select"]);
this.on('select', this.menuHide, this);
if(this.handler){
this.on('select', this.handler, this.scope || this);
}
}
});
}else{
Ext.menu.DateTimeItem = function(config){
Ext.menu.DateTimeItem.superclass.constructor.call(this, new Ext.DateTimePicker(config), config);
this.picker = this.component;
this.addEvents('select');

this.picker.on("render", function(picker){
picker.getEl().swallowEvent("click");
picker.container.addClass("x-menu-date-item");
});

this.picker.on("select", this.onSelect, this);
};

Ext.extend(Ext.menu.DateTimeItem, Ext.menu.DateMenu, {
onSelect : function(picker, date){
this.fireEvent("select", this, date, picker);
Ext.menu.DateTimeItem.superclass.handleClick.call(this);
}
});
}

Ext.menu.DateTimeMenu = function(config){
Ext.menu.DateTimeMenu.superclass.constructor.call(this, config);
this.plain = true;
var di = new Ext.menu.DateTimeItem(config);
this.add(di);
this.picker = di;
this.relayEvents(di, ["select"]);

this.on('beforeshow', function(){
if(this.picker){
this.picker.hideMonthPicker(true);
}
}, this);
};
Ext.extend(Ext.menu.DateTimeMenu, Ext.menu.Menu, {
cls:'x-date-menu',
beforeDestroy : function() {
this.picker.destroy();
},
hide : function(deep){
if (this.picker.tf.innerList){
if ((Ext.EventObject.within(this.picker.tf.innerList)) || (Ext.get(Ext.EventObject.getTarget())==this.picker.tf.innerList))
return false;
}
if(this.el && this.isVisible()){
this.fireEvent("beforehide", this);
if(this.activeItem){
this.activeItem.deactivate();
this.activeItem = null;
}
this.el.hide();
this.hidden = true;
this.fireEvent("hide", this);
}
if(deep === true && this.parentMenu){
this.parentMenu.hide(true);
}
}
});

Ext.ux.form.DateTimeField = Ext.extend(Ext.form.DateField, {
dateFormat: 'Y-m-d'
,timeFormat: 'H:i:s'
,defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"}
,initComponent:function() {
Ext.ux.form.DateTimeField.superclass.initComponent.call(this);
this.format = this.dateFormat + ' ' + this.timeFormat;
this.afterMethod('afterRender',function(){
this.getEl().applyStyles('top:0');
});
}
,getValue : function(){
return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || '';
}
,onTriggerClick : function(){
if(this.disabled){
return;
}
if(this.menu == null){
this.menu = new Ext.menu.DateTimeMenu();
}
Ext.apply(this.menu.picker, {
minDate : this.minValue,
maxDate : this.maxValue,
disabledDatesRE : this.ddMatch,
disabledDatesText : this.disabledDatesText,
disabledDays : this.disabledDays,
disabledDaysText : this.disabledDaysText,
format : this.format,
timeFormat: this.timeFormat,
dateFormat: this.dateFormat,
showToday : this.showToday,
minText : String.format(this.minText, this.formatDate(this.minValue)),
maxText : String.format(this.maxText, this.formatDate(this.maxValue))
});
if (this.menuEvents) {
this.menuEvents('on');
}
else {
this.menu.on(Ext.apply({}, this.menuListeners, {
scope:this
}));
}
this.menu.picker.setValue(this.getValue() || new Date());
this.menu.show(this.el, "tl-bl?");
}
});
Ext.reg('datetimefield', Ext.ux.form.DateTimeField);


分享到:
评论

相关推荐

    EXTJS日期扩展年月和年月日时分秒

    扩展日期选择时分秒--dateTimeField4.0.html (这个只在EXTJS4.0下显示可以) EXTJS4.1文件夹下面包括 1.只有年月选择--dateYM.html (这个在EXTJS4.0和4.1下显示都是可以的) 2.扩展日期选择时分秒--...

    Extjs 年月日时分秒组件

    Extjs时间选择插件精确到时分秒,里面有详细的使用步骤

    extjs4.2 日期控件扩展带时分秒

    extjs4.2 日期控件扩展,带年月日时分秒的选择。

    EXTJS时间控件年月日时分秒

    EXTJS时间年月日时分秒控件。内附详细的使用说明。供大家参考学习。

    EXTJS5 日期时分秒控件

    EXTJS5 日期时分秒控件,直接引用到程序中使用。网上有很多extjs4版本的和EXTJS5不兼容。调用实例代码: {labelWidth:60,width: 220,name:'mydate',fieldLabel: '日期',allowBlank: false,xtype: 'datetimefield',...

    extjs4.*完美时间日期控件,可选时分秒

    网上找了一些,不是运行不了,就是代码繁多复杂。所以自己试着写了一个扩展的时间日期控件,可选时分秒,包含项目源代码,下载可直接运行·

    ExtJs4.2.1年月日时分秒、时分秒控件

    ExtJs4.2.1年月日时分秒、时分秒控件;附件中包含控件的css和js文件; test.html为测试样例,需要改变引入extjs的路径。

    Extjs5.1版本时间时分秒控件

    Extjs时间控件可选年月日时分秒,哪个版本都可使用,谢谢使用

    Extjs4.2 带时分秒的日期插件

    这个插件是张川(cr10210206@163.com)做的,我只是做了一个小修改,修正了点击“现在”按钮的时候,只有日期变成今天,时间不会变成现在的小BUG。 谢谢张川 多谢CSDN上面的资源。

    Extjs4.2带时分秒的插件

    公司让做一个带有时分秒的时间插件,忘了看了很多例子,一般都是基于4.0乃至更早的版本封装的,这个是基于4.2最新版本封装,测试可用,在IE8上显示有些问题,自己调整一下就好了,我调整一下布局,在iE8上也可以了

    extjs4.2 日期控件 datefield 拓展加上选择时分秒功能

    在ExtJs4.2表单控件里分别有个时间控件(datafield)和时间控件(timefield),但是官方提供的控件不能将日期和时分秒整合到一起,我从网上搜集整理了一个可用的选择日期时分秒的拓展控件,extjs版本是4.2,亲测能用,...

    ExtJs4.0.7年月日时分秒、时分秒控件

    ExtJs4.0.7年月日时分秒、时分秒控件;附件包含css、js和测试样例文件。

    extjs5 带时分秒(datetimefield)

    extjs5 带时分秒扩展.下载解压完之后 放到自己所需的文件夹,调用的话直接在app.js中requires:['Platform.utils.DatetimeField','Platform.utils.DatetimePicker'] .在需要用到该时间控件的地方{xtype:'datetimefield...

    Extjs4.2时间选择插件精确到时分秒

    Extjs4.2时间选择插件精确到时分秒,4的版本以上应该都可以用,不够需要jquery的支持,我想您的项目一定是引入jquery的吧。

    extjs时间控件精确秒

    extjs时间空间精确秒

    extjs4.2 datetime控件

    extjs4.2的日期扩展插件,支持时分秒显示。支持动态赋值

    extjs多选 下拉框扩展

    extjs多选 下拉框扩展

    extjs4.2日期控件datefield拓展加上选择时分秒功能

    在ExtJs4.2表单控件里分别有个时间控件(datafield)和时间控件(timefield),但是官方提供的控件不能将日期和时分秒整合到一起,我从网上搜集整理了一个可用的选择日期时分秒的拓展控件,extjs版本是4.2,亲测能用,...

    extjs3.0 中扩展的日期控件

    由于extjs3.0自己封装的时间不能够选择时分秒,给大家开发带来了一些麻烦。虽然网上有ext2.0的日期扩展控件,但...公司现在项目正用了,因此我就对extjs3.0时间控件的扩展,实现了可选择时分秒功能。希望对大家有帮助。

    ExtJs中datetimefield扩展

    ExtJs中datetimefield扩展,不缺少任何文件,可以直接浏览效果,查看扩展代码

Global site tag (gtag.js) - Google Analytics