Infragistics WebDataGrid/WHDG controls for ASP.NET offer nice filtering features. Out of the box you just have to enable the behavior and badabingo:
There is one glitch though in the way text filtering is implemented: If you enter an empty string as a filter value – an error is thrown:
Async refresh failed. Length cannot be less than zero
Apparently internal grid code cannot handle empty strings (as of version 12.2) so we have to take matter in our own hands.
Add following code to your grid’s
DataFiltering event handler:
Protected Sub xMyGrid_DataFiltering(sender As Object, e As GridControls.FilteringEventArgs) Handles xMyGrid.DataFiltering For I As Integer = e.ColumnFilters.Count - 1 To 0 Step -1 If e.ColumnFilters(I).ColumnType = "string" Then If DirectCast(e.ColumnFilters(I).Condition, GridControls.RuleTextNode).Value = "" Then e.ColumnFilters.RemoveAt(I) End If End If Next 'rebind the grid to datasource as needed End Sub
Essentially what is happening here – we loop thru all column filters, check if it’s a text column and if it is – check its filter ‘s value. If it’s an empty string – we simple removing the filter from the collection. Error is gone, filter is performed as expected.