If I have to put an AutoFilterCondition of "Contains" for all the columns in the grid, there is not easier way than putting the line:
ASPx<Settings AutoFilterCondition="Contains" />
inside each column. This is pretty annoying as one can have a dozen columns in the grid, and to specify filtering conditions for each column can be a pain.
TEMPORARY SOLUTION:
When defining the ASPxGridView.Columns collection manually (AutoGenerateColumns="False"), it is possible to change the default AutoFilterCondition in the following manner:
- Handle the ASPxGridView.Init event;
- Iterate through all GridViewDataColumns in the ASPxGridView.Columns;
- Change the AutoFilterCondition (for example, set it to the "Contains"):
ASPx<dx:ASPxGridView ID="gv" AutoGenerateColumns="False" OnInit="gv_Init">
C#protected void gv_Init(object sender, EventArgs e) {
ASPxGridView gridView = (ASPxGridView)sender;
foreach(GridViewColumn column in gridView.Columns) {
if(column is GridViewDataColumn) {
((GridViewDataColumn)column).Settings.AutoFilterCondition = AutoFilterCondition.Contains;
}
}
}
Visual BasicProtected Sub gv_Init(ByVal sender As Object, ByVal e As EventArgs)
Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
For Each column As GridViewColumn In gridView.Columns
If TypeOf column Is GridViewDataColumn Then
CType(column, GridViewDataColumn).Settings.AutoFilterCondition = AutoFilterCondition.Contains
End If
Next column
End Sub
When binding the ASPxGridView.Columns automatically from the datasource (AutoGenerateColumns="True"), it is possible to change the default AutoFilterCondition in the following manner:
- Handle the ASPxGridView.DataBound event;
- Iterate through all GridViewDataColumns in the ASPxGridView.Columns;
- Change the AutoFilterCondition (for example, set it to the "Contains"):
ASPx<dx:ASPxGridView ID="gv" ... AutoGenerateColumns="True" OnDataBound="gv_DataBound">
C#protected void gv_DataBound(object sender, EventArgs e) {
ASPxGridView gridView = (ASPxGridView)sender;
foreach(GridViewColumn column in gridView.Columns) {
if(column is GridViewDataColumn) {
((GridViewDataColumn)column).Settings.AutoFilterCondition = AutoFilterCondition.Contains;
}
}
}
Visual BasicProtected Sub gv_DataBound(ByVal sender As Object, ByVal e As EventArgs)
Dim gridView As ASPxGridView = CType(sender, ASPxGridView)
For Each column As GridViewColumn In gridView.Columns
If TypeOf column Is GridViewDataColumn Then
CType(column, GridViewDataColumn).Settings.AutoFilterCondition = AutoFilterCondition.Contains
End If
Next column
End Sub
Proposed Solution:
Have a grid-level setting for AutoFilterCondition as well i.e.
<Grid>
<Settings AutoFilterCondition="BeginsWith or Contains … etc"/>
</Grid>
When column level settings for filtering are specified even though grid level setting is in place, the column level setting will override the grid-level setting.
For e.g.
<Grid>
<Settings AutoFilterCondition="Contains"/>
<Columns>
<Column1 …>
<Settings AutoFilterCondition="Equals"/>
</Column1>
<Column2 …></Column2>
</Columns>
</Grid>
In the above case Column2 will still do a "Contains" filtering, but Column1 will perform an "Equals" filtering.
I would second this request - adding yet more event handlers to a page is not a very elegant solution to what I assume is a common use case. This should be pretty trivial to implement, I'd assume, since there are other settings that apply to all the columns (for example, you have autoFilterInputDelay implemented at the grid level, but not AutoFilterCondition).
I agree. It would be great to be able to define default column settings at the grid level.
I fourth that suggestion. Couldn't come quick enough with multiple large gridviews on a page.
+1.
I agree with the solution. I ran into the issue and had to change this setting for every single column.
+1.
+1.