Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to add custom filter items into the DateTime filter popup window

$
0
0

In the latest versions, you can use the ShowFilterPopupDate event to add a custom filter item to the filter dropdown. See the ShowFilterPopupDate topic for additional information and code snippet.


------------------------------------------------------------------------
This example demonstrates how to add the capability to enter "greater than", "less than", and "between" directly from the calendar popup filter list.

To provide this functionality, it is necessary to create a GridControl descendant with a custom MyGridView.

First, override the MyGridView.CreateDateFilterPopup and MyGridView.RaiseFilterPopupDate methods.

[C#]
protectedoverrideDateFilterPopupCreateDateFilterPopup(GridColumncolumn,System.Windows.Forms.ControlownerControl,objectcreator){returnnewMyDateFilterPopup(this,column,ownerControl,creator);}

In the MyGridView.RaiseFilterPopupDate method add required FilterCriteria.

[C#]
protectedoverridevoidRaiseFilterPopupDate(DateFilterPopupfilterPopup,List<FilterDateElement>list){CriteriaOperatorfilter=newBinaryOperator(filterPopup.Column.FieldName,DateTime.Today,BinaryOperatorType.Greater);list.Add(newFilterDateElement(Localizer.Active.GetLocalizedString(StringId.FilterClauseGreater),"",filter));filter=newBinaryOperator(filterPopup.Column.FieldName,DateTime.Today,BinaryOperatorType.Less);list.Add(newFilterDateElement(Localizer.Active.GetLocalizedString(StringId.FilterClauseLess),"",filter));filter=newBetweenOperator(filterPopup.Column.FieldName,DateTime.Today,DateTime.Today);list.Add(newFilterDateElement(Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween),"",filter));base.RaiseFilterPopupDate(filterPopup,list);}

Now, the CreateDateFilterPopup method returns the MyDateFilterPopup object instead of the DateFilterPopup one.

Override the Popup.CreateRepositoryItem method to create additional controls and add handlers for them:

[C#]
protectedoverrideRepositoryItemPopupBaseCreateRepositoryItem(){item=base.CreateRepositoryItem()asRepositoryItemPopupContainerEdit;if(DateFilterControl.Controls.Count> 0){DateCalendar1=CreateCalendar(DateCalendar1,DateCalendar.SelectionStart,DateCalendar.Top,DateCalendar.Left);DateCalendar1.Visible=false;DateCalendar2=CreateCalendar(DateCalendar2,DateCalendar.SelectionStart,DateCalendar1.Top,DateCalendar.Left+DateCalendar1.Width);DateCalendar2.Visible=false;Greater=GetCheckEditByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseGreater));Less=GetCheckEditByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseLess));Between=GetCheckEditByName(Localizer.Active.GetLocalizedString(StringId.FilterClauseBetween));Greater.CheckedChanged+=CheckedChanged;Less.CheckedChanged+=CheckedChanged;Between.CheckedChanged+=CheckedChanged;foreach(ControlctrlinDateFilterControl.Controls){if(ctrlisCheckEdit)if(NotOurControl(ctrlasCheckEdit))(ctrlasCheckEdit).CheckedChanged+=OriginalDateFilterPopup_CheckedChanged;}}returnitem;}

When a custom item's check state changes, update the popup window layout to display the calendar at a required place.

[C#]
voidCheckedChanged(objectsender,EventArgse){if((senderasCheckEdit).Checked){UpdateOurControlCheckedState((senderasCheckEdit).Text);CalcControlsLocation((senderasCheckEdit).Text);this.View.ActiveFilterCriteria=GetFilterCriteriaByControlState();}else{if(DateCalendar1.Visible||DateCalendar2.Visible){ReturnOriginalView();ReturnOriginalControlsLocation();}}}

 


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>