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 Stefano,
I'm not sure about the order of things - whether the grid sorts first or filters first. It's probably arbitrary. I can see how you might want it to work either way. You might want a "Top n" filtered column to sort first and then filter, or filter first and then sort. It might also depend on what order you set the properties on the grid. If you sort the column and then filter, it will probably work that way and vice versa.
Either way, I think the custom FilterCondition might work. What you do is derive a class from FilterCondiftion and override the MeetsCriteria method. This method passed you a reference to the row, so you could use the row.VisibleIndex to determine whether or not to filter it.
To put a custom condition on the dropdown list, you handle the BeforeRowFilterDropDown or BeforeRowFilterDropDownPopulate event and add an item to the ValueList passed to you in the event args. The item you add is a ValueListItem, so you pass in whatever text you want as the DislpayText and an instance of your custom FilterCondition as the DataValue.
Hi Mike,
thanks for the tip. I tried it, but it is not exactly what I am looking for. First of all, either event is triggered only when I use the "funnel" filter, and not the row filter. Then, I am more interested in having it added to the combos in a row filter, where I'd like to see a "Top" operator, and the user would type in a number (10, 20, etc...).
Both of these events fire whenever you drop down the Operand list. It doesn't matter if you do it via the Filter icon in a column header or in a Filter Row.
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.
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.