Hi all,
I am trying to figure out how to implement a "top n" filter. This is usually in conjunction with a sorted column, so that you can have the grid sort first then apply a filter to show only the first ten rows. However, I seem to understand that the WinGrid first applies the filter then it applies sort. Is there a way to implement this feature by using a FilterCondition, and make it available to the end user in the filter UI?
Thanks,
Stefano.
Hi Brian,
This works. In combination with clearing the filtercondition in the BeforeSortChange and setting it again in the AfterSortChange.
Erik
The following code sample demonstrates how to use a custom FilterCondition-derived class to limit the number of rows displayed by an arbitrary number:
#region TopNFilterCondition class/// <summary>/// Infragistics.Win.UltraWinGrid.FilterCondition-derived class which/// provides a way to use row filtering to limit the number of rows displayed./// </summary>public class TopNFilterCondition : FilterCondition{ private int maxRows = 10;
public TopNFilterCondition( int maxRows ) { this.maxRows = maxRows; }
public override bool MeetsCriteria( UltraGridRow row ) { return row.Index < this.maxRows; }}#endregion TopNFilterCondition class
I don't know how to get this into the filter UI or if that is even possible, but I think we added the abilty to plug your own filter UI in there by implementing the Infragistics.Win.UltraWinGrid.IFilterUIEProvider interface, although that might require more work than you bargained for.
Hi,
I also tried to create a 'TOP N' filter.
What I did was the following: create a FilterCondition like this:
<Serializable()> _
Private Class RowCountFilterCondition
Inherits FilterCondition
Private maxRows As Integer
Protected Sub New( _
ByVal info As System.Runtime.Serialization.SerializationInfo, _
ByVal context As System.Runtime.Serialization.StreamingContext)
MyBase.New(info, context)
End Sub
Sub New(ByVal column As UltraGridColumn, ByVal count As Integer)
MyBase.New(Column, FilterComparisionOperator.Custom, Nothing)
maxRows = count
Public Overrides Function MeetsCriteria(ByVal row As UltraGridRow) As Boolean
If (row.VisibleIndex < maxRows) Then
Return 1
Else
Return 0
End If
End Function
End Class
Now I added some extra code to handle the order that I want: first sort on the complete data, then filter. So I clear the filter in the BeforeSortChange like this:
UltraGrid1.DisplayLayout.Bands(0).ColumnFilters(filterCol).FilterConditions.Clear()
and then set it again in the AfterSortChange like this:
UltraGrid1.DisplayLayout.Bands(0).ColumnFilters(filterCol).FilterConditions.Add(New RowCountFilterCondition(UltraGrid1.DisplayLayout.Bands(0).Columns(filterCol), 2))
Hi Stefano,
I don't beleive it's possible to add your own operators. The operators are defined by an enum, so there's no way to edit it.
You can add an Operand to the list that contains a custom FilterCondition, though. It would be similar to how the "(All)" or "(Blanks)" options work. What you do is derive a class from FilterCondition and override the MeetsCriteria method. Then you use the BeforeRowFilterDropDown or BeforeRowFilterDropDownPopulate event to add an item to the list. The item's DataValue would be an instance of your FilterCondition class and the DisplayText is whatever you want the user to see.
Hi Mike,
sorry for not being clear. You are right that those events are fired whenever you open up the Operand combo in both filter modes. What I want to do is to add a new filter Operator, like "Equals" or "MatchesRegular Expression", that accepts a numeric operand input by the user.