Implementation of extjs time range Selection

Source: Internet
Author: User

In extjs, you sometimes need to select a date range and automatically determine that the selected start date cannot be greater than the end date, or the end date cannot be smaller than the start date. The implementation code is as follows:


:


As you can see, when a start time is selected, the range of the end time is automatically limited to achieve the association of two date selectors.

The Code is as follows: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD48cD7K18/ItqjS5cGqtq + 0 psDtuq/K/To8L3A + PHA + PGJyIC8 + pc9wpjxwp1_vcd48chjlignsyxnzpq = "brush: java;"> 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 earlier than end date'}); Ext. tip. quickTipManager. init ();

Add the following to items in tbar, bbar, or form:


{Xtype: 'datefield ', fieldLabel: 'start time range', name: 'startdt ', id: 'startdt', vtype: 'daterange ', endDateField: 'enddt ', format: 'Y-m-d', width: 220, labelWidth: 90, msgTarget: 'day', autoFitErrors: false}, {xtype: 'datefield ', fieldLabel: 'end', name: 'enddt', id: 'enddt', vtype: 'daterange ', startDateField: 'startdt', format: 'Y-m-d', width: 170, labelWidth: 40, msgTarget: 'day', autoFitErrors: false}, {xtype: 'call', text: 'query', iconCls: 'fljs', handler: function (){...


You can achieve the above results. This code is copied and 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.