Adding Filters to Your QDataGrid
Now, we will add a filter bar to our datagrid.
Enabling the filter bar is as easy as setting the datagrid's
ShowFilter property to true.
Specifying the filters to use is all that's left.
While creating the datagrid's columns, you can also specify a filter to use for that column.
These can either be custom filters for you to handle yourself, or
QConditions (specifically, any
QQConditionComparison) for your use with QQuerys. We'll be looking at the latter in this example.
So the first step is defining the filters. In this example, we set up an
Equal filter for the
Person Id and
Like filters for the name columns. Note that if you just want to use the default
filter for that database column's type, you can just use the node's
SetFilteredDataGridColumnFilter
function, as shown for the Last Name column.
Then, in our
dtgPersons_Bind function we just make sure we use the conditions the datagrid
provides us with. And there you have it, a filtered data grid.
But know what's even easier than that? The
MetaDataGrids generated for you already include these
filters by default! Any time you use
MetaAddColumn, it will set any appropriate filters for that
column without a single line of extra code on your part. :) See the
Introduction to Meta DataGrids for more information.