Friday, October 16, 2015

Set the filtering at a DevExpress ASPxGridView to filter by "Contains" instead of "Begins with" in C#.

As this and this suggest, there is a way to set the default operator for filtering like so:

protected void ReviseColumnFilterOperators(ASPxGridView grid)
{
   foreach (GridViewColumn column in grid.Columns)
   {
      ReviseColumnFilterOperator((dynamic)column);
   }
}
 
private void ReviseColumnFilterOperator(GridViewColumn column)
{
}
 
private void ReviseColumnFilterOperator(GridViewDataColumn column)
{
   column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
}
 
private void ReviseColumnFilterOperator(GridViewDataTextColumn column)
{
   column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
}

 
 

For string data, the default operators are:

  1. Begins with
  2. Contains
  3. Doesn't contain
  4. Ends with
  5. Equals
  6. Doesn't equal

 
 

I'm not yet sure how to change these but for the string scenario these seem like pretty good choices. One may toggle to "Begins with" that key icon at the right of a filter box and one may then toggle back to "Contains" easily enough. For numeric data however, the defaults seem to be:

  1. Equals
  2. Doesn't equal
  3. Is less than
  4. Is less than or equal to
  5. Is greater than
  6. Is greater than or equal to

 
 

...and yet, if one picks a different way to filter and then clears the field and leaves it and returns the filtering will fall back to "Contains" as it just takes a little more work to clear a setting in this regard. (well, reset by callbacks perhaps... it all depends how you do this) There are ways to conditionally check to see if a column's data point of a particular type (if you want to exclude the "Contains" logic at the numeric columns) as suggested here here and here, and that may come in handy if you are like me and are not making a different column type for each different type of data point. I didn't know there was such a thing as a GridViewDataDateColumn until I started researching all this.

No comments:

Post a Comment