Filter Grouping is a methods of reducing the amount of records that appear
in a selection list by grouping them into predefined group.
While filtering in general will be very useful, as a method, grouping will probably
be the least useful of all of the filtering methods availabe because it is very limited.
Having said that give it a try on this page and see if it works for you.
Note: that at this time filtering only works on the Search list and no other selection
lists.
As with all filtering, to set up filter groups requires making a call to
the setFilterGroup method after creating the selection list.
To see how to setup a filter group lets look at the example.
In our example we have a person form and we want to filter the search list by lastnames.
Firstly we create the search list:
$dbForm->setSearchField("personid","select personid, lastname, firstname from person
where canceldate is null and (1=1) order by lastname, firstname", ", ", "Select a
Person", true);
Note that we have included (1=1) in the query. This is a replacement tag that will be replaced with a valid where clause during the filter process.
Next we need to call setFilterGroup
$dbForm->setFilterGroup("personid","lastname",array("A..G","H..O","N..Z"),"(1=1)",
"Select a Filter Group");
Lets now look at this to see what it is doing
$field = "personid" which tells setFilterGroup to filter the personid field.
$filterField = "lastname" which tells setFilterGroup to use lastname as the field
to replace in the search query.
$filterGroup = array("A..G","H..O","N..Z") which tells setFilterGroup to use 3 filter
groups consiting of A to G, H to O and N to Z.
$filterReplace = "(1=1)" which tells setFilterGroup to replace (1=1) in the search query
with a where clause on the $filterField field (i.e. lastname)
$defaultText = "Select a Filter Group" which tells setFilterGroup to display this text
at the start of the list.
When run this example will display a filter list consisting of the default text and the 3
specified groups, then once a group is selected the SearchField query will be run with the
filterReplace tag replaced with a where clause and a reset filter item is added to the end
of the list.
i.e. if group H..O is select then the Search Field query will look as follows
select personid, lastname, firstname from person
where canceldate is null and (lastname between 'H' and 'Oz') order by lastname, firstname
Note: O is changed automatically to Oz to ensure that the O group is acutally found
Be warned that if there are records that do not fall into these groups then they will not be able to be found with this filter method. This is the main limitation of Filter Groups
View source code for demo4.php
The template for this demonstration is fairly straight forward however it does use a new feature introduced in dbForm 0.8.2. It has the ability to incorporate attributes in the dbForm tags.
For example if we want a field to be displayed with a class and a specific style we can now incorporate that into the template rather than having to specify it in code. This makes the templates as flexible as possible.
In this example we are adding a class and style to a named field tag
{:field="firstname" class="content2" style="width:140px;"}
This will be replaced in the output html as something like:
<input type="text" name="firstname" value="Tony" class="content2" style="width:140px;" />
This allows almost all formatting to be controlled via the template if required.
View source code for demo4.tpl
The files that have been used in this demonstration can be downloaded so you can try them out for yourself.