dbForm PHP Project
Filter Paging Demonstration

Filter Paging is a methods of reducing the amount of records that appear in a selection list by grouping them into pages of a set number of records.
Note: that at this time filtering only works on the Search list and no other selection lists.


Person
Search:
 
Source Code

As with all filtering, to set up filter paging requires making a call to the setFilterPaging 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 with 10 records per group.

Firstly we create the search list:
$dbForm->setSearchField("personid","select personid, lastname, firstname from person where canceldate is null order by lastname, firstname", ", ", "Select a Person", true);

Next we need to call setFilterPaging
$dbForm->setFilterPaging("personid",10,"Select a Filter Group");

Lets now look at this to see what it is doing
$field = "personid" which tells setFilterPaging to filter the personid field.
$pageSite = 10 which tells setFilterPaging to filter with 10 records per group.
$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 an item for each group consisting of the first and last item from the group, then once a group is selected the SearchField query will be run with a select limit query used (or simulated by ADODB) to get the records from the group.

When displaying the filter groups only the first of the display fields from the query will be displayed. So in this example only the lastname will be display and it will show the first and last lastname from the group
i.e. If the first records is Adams, Morticia and the 10th records is Jones, Jimbo then when filtering the group will be shown as Adams - Jones

Be warned this method of filtering need to calculate the filter groups every time it is displaying the filter os if a very large recordset with small pageSize is used this may be slow.

View source code for demo5.php

Template File

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 demo5.tpl

Download Demo files

The files that have been used in this demonstration can be downloaded so you can try them out for yourself.

demo5.zip