Implementation of ExtJS time range selection

Source: Internet
Author: User

ExtJS sometimes need to select a date range, you need to automatically judge, the selected start date can not be greater than the end date, or the end date cannot be less than the start date, the implementation of the code is as follows


:


As you can see, when a start time is selected, the selection of the end time is automatically restricted, enabling the linkage of the two date selectors.

The code is as follows:

First define the linkage handler function:


 Ext.apply (Ext.form.field.VTypes, {daterange:function (val, field) {            var date = Field.parsedate (val);            if (!date) {return false; } if (Field.startdatefield && (!this.daterangemax | | (Date.gettime ()! = This.dateRangeMax.getTime ())))                {var start = field.up (' grid '). Down (' # ' + Field.startdatefield);                Start.setmaxvalue (date);                Start.validate ();            This.daterangemax = date; } else if (Field.enddatefield && (!this.daterangemin | | (Date.gettime ()! = This.dateRangeMin.getTime ())))                {var end = field.up (' grid '). Down (' # ' + Field.enddatefield);                End.setminvalue (date);                End.validate ();            This.daterangemin = date;        } return true;    }, Daterangetext: ' Start date must be less than end Date '}; Ext.tip.QuickTipManager.init (); 


Add in items in Tbar,bbar or form:


        {            xtype: ' Datefield ',            Fieldlabel: ' Time range start ',            name: ' Startdt ',            ID: ' Startdt ',            vtype: ' DateRange ',            Enddatefield: ' ENDDT ',            format: ' y-m-d ',            width:220,            labelwidth:90,            msgtarget: ' Side ',            Autofiterrors:false        }, {            xtype: ' Datefield ',            fieldlabel: ' End ',            name: ' ENDDT ',            ID: ' ENDDT ',            vtype: ' DateRange ',            startdatefield: ' Startdt ',            format: ' y-m-d ',            width:170,            labelwidth:            msgtarget: ' side ',            autofiterrors:false        }, {xtype: ' button ',            text: ' Query ',            iconcls: ' Fljs ',            handler:function () {...


Can achieve the above effect this code copy runs in extjs4.1.1


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.