ExtJS4.2学习(18)时间控件

在ExtJs4.2表单控件里有个时间控件,但是官方提供的控件不能将日期和时分秒整合到一起,我从网上搜集整理了几个可用的控件。先来看下4.2自带的是什么效果:

QQ截图20131222175510.jpg

上面的控件一点都不方便,而且选择的时候还不能精确到秒,以下是代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< meta  http-equiv = "Content-Type"  content = "text/html; charset=UTF-8" >
< title >Hello Extjs4.2</ title >
< link  href = "../../ExtJS4.2/resources/ext-theme-neptune/ext-theme-neptune-all.css"  rel = "stylesheet" >
< script  src = "../../ExtJS4.2/ext-all.js" ></ script >
< script  src = "../../ExtJS4.2/locale/ext-lang-zh_CN.js" ></ script >
< script  type = "text/javascript" >
Ext.onReady(function(){
                                           
     var field = new Ext.form.TextField({
         fieldLabel: 'empty', //输入控件前显示名称
         allowBlank: false, //是否允许为空
         emptyText:'空', //没有输入任何内容提示文字
         maxLength:50, //输入最大字符串长度
         minLength:10 //输入最小字符串长度
     });
                                               
     var fieldTextArea = new Ext.form.TextArea({
         width:200,
         grow:true, //会根据输入内容自动修改自身高度
         preventScrollbars:true, //防止出现滚动条,如果内容超出显示范围就会自动隐藏
         fieldLabel:'empty',
         allowBlank:false,
         emptyText:'空',
         maxLength:50,
         minLength:10
     });
                                               
     var fieldDate = new Ext.form.DateField({
         fieldLabel:'日期',
         emptyText:'请选择',
         format:'Y-m-d',
         disabledDays:[0,6] //禁止选择的日期
     });
                                               
     var timeDate = new Ext.form.TimeField({
         fieldLabel:'时间',
         emptyText:'请选择',
         format:'H:i:s',
         increment:1 //时间颗粒度
     });
                                           
     var form = new Ext.form.FormPanel({
         title: '表单输入控件演示',
         width:500,
         frame: true,
         items: [field,fieldTextArea,fieldDate,timeDate],
         renderTo: 'form'
     });
});
</ script >
</ head >
< body >
< h1 >我的ExtJS4.2学习之路</ h1 >
< hr  />
作者:束洋洋
开始日期:2013年12月11日21:13:50
< h2 >深入浅出ExtJS之文本输入控件Ext.form.TextField</ h2 >
< div  id = "form" ></ div >
</ body >
</ html >

这里介绍下increment属性,这个属性是控制时间颗粒度的,默认为15,我这里改为了1,也就是可以选择1分钟,但是秒还是选择不了。在ExtJs3.2中,网上有些人才写了些扩展控件,我发现非常好,但是非常遗憾,4.2用不了,3.X和4.x区别还是挺大的,具体的区别大家可以上网搜下看看。这里我把3.2的例子也提供给大家,点此下载

QQ截图20131222175942.jpg

好了,现在再看下苦逼的4.2,第一种,下载地址在这里【点击这里


QQ截图20131222180201.jpg

第二种,下载地址在这里【点击下载

QQ截图20131222180622.jpg

这种调用方式,这里给大家发一下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html >
< head >
< meta  http-equiv = "Content-Type"  content = "text/html; charset=UTF-8" >
< title >Hello Extjs4.2</ title >
< link  href = "../../ExtJS4.2/resources/ext-theme-neptune/ext-theme-neptune-all.css"  rel = "stylesheet" >
< script  src = "../../ExtJS4.2/ext-all.js" ></ script >
< script  src = "../../ExtJS4.2/locale/ext-lang-zh_CN.js" ></ script >
            
< script  type = "text/javascript"  src = "../../myplugin/dateTimeFileld/ux/UX_TimePickerField.js" ></ script >
< script  type = "text/javascript"  src = "../../myplugin/dateTimeFileld/ux/UX_DateTimePicker.js" ></ script >
< script  type = "text/javascript"  src = "../../myplugin/dateTimeFileld/ux/UX_DateTimeMenu.js" ></ script >
< script  type = "text/javascript"  src = "../../myplugin/dateTimeFileld/ux/UX_DateTimeField.js" ></ script >
< script  type = "text/javascript" >
Ext.onReady(function(){
     Ext.Loader.setConfig({enabled:true});
     Ext.Loader.setPath('MyApp', '../houtai/js');
     Ext.define('MyApp.ux.DateTimeField', {
           extend: 'Ext.form.field.Date',
           alias: 'widget.datetimefield',
           requires: ['MyApp.ux.DateTimePicker'],
           initComponent: function() {
               thisthis.format = this.format;
               this.callParent();
           },
           // overwrite
           createPicker: function() {
               var me = this,
                   format = Ext.String.format;
               return Ext.create('MyApp.ux.DateTimePicker', {
                     ownerCt: me.ownerCt,
                     renderTo: document.body,
                     floating: true,
                     hidden: true,
                     focusOnShow: true,
                     minDate: me.minValue,
                     maxDate: me.maxValue,
                     disabledDatesRE: me.disabledDatesRE,
                     disabledDatesText: me.disabledDatesText,
                     disabledDays: me.disabledDays,
                     disabledDaysText: me.disabledDaysText,
                     format: me.format,
                     showToday: me.showToday,
                     startDay: me.startDay,
                     minText: format(me.minText, me.formatDate(me.minValue)),
                     maxText: format(me.maxText, me.formatDate(me.maxValue)),
                     listeners: {
                         scope: me,
                         select: me.onSelect
                     },
                     keyNavConfig: {
                         esc: function() {
                             me.collapse();
                         }
                     }
                 });
           }
       });
     var form = new Ext.form.FormPanel({
         title: '表单输入控件演示',
         width:500,
         frame: true,
         items: [{
             xtype:'datetimefield',
             width : 300,
             labelWidth : 80,
             endDateField:'etime',
             vtype:'daterange',
             fieldLabel: '开始时间',
             format: 'Y-m-d H:i:s ',
             name:'stime'
         },
         {
             xtype:'datetimefield',
             width : 300,
             labelWidth : 80,
             startDateField:'stime',
             vtype:'daterange',
             fieldLabel: '结束时间',
             format: 'Y-m-d H:i:s ',
             name:'etime'
         }],
         renderTo: 'form'
     });
});
</ script >
</ head >
< body >
< h1 >我的ExtJS4.2学习之路</ h1 >
< hr  />
作者:束洋洋
开始日期:2013年12月11日21:13:50
< h2 >深入浅出ExtJS之文本输入控件Ext.form.TextField</ h2 >
< div  id = "form" ></ div >
</ body >
</ html >

虽然解决了日期和时分秒的问题,但是体验还是有点差,囧。。。(4.2的控件必须先选择时分秒,再选择日期才可以,网上搜索了许多,希望可以有个带确定按钮的,但是都以失败告终,有些不符合,有些不能用,你如果找到了,请告诉我哈~)



本文转自shyy8712872 51CTO博客,原文链接:http://blog.51cto.com/shuyangyang/1404958,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值