Add Filters to the Bootstrap admin list view

PHPCG allows to add filters to your end-user's Admin READ lists within a few clicks.


Summary

Prerequisites

To add filters to your admin panel READ lists with PHPCG you must beforehand:

CRUD sample database diagram
CRUD sample database diagram

Admin READ lists Filters

PHPCG offers two ways to add dropdown lists to filter your records in your Admin READ lists:

  • Simple filters
  • Advanced filters

The simple filters

You can use them to filter your list using any field of the current table.

For example you can filter articles by id, title or publish date.

The Advanced filters

You can use them to filter your list using any field of any related table.

To create an "advanced filter" you have to build a custom SQL query to get the value you want to use in your filter dropdown list.


Enter the values in the CRUD Generator (Build READ List => add filter => advanced):

Label
The dropdown list label displayed in the Admin Panel.
ie: Author
Value(s)
The values displayed in the option dropdown list, separated by the "+" sign.
ie: authors.name + authors.first_name
Fields
The fields used in your SELECT statement.
ie: authors.name, authors.first_name, articles.authors_id
Fields to be filtered
The option value used to filter the list.
ie: articles.authors_id
SQL FROM
The SQL FROM statement used to get the records.
ie: articles INNER JOIN authors ON articles.authors_id = authors.id
Column number
The index of the column in your Admin Panel READ list.
ie: 2
Type of values
Text or Boolean

In the previous example we want to display a dropdown list with Authors names + first names to filter the articles READ list by author_id, where author_id is the foreign key.

FlySpeed SQL Query will help to generate and test your queries

PHP CRUD tutorial main page