- Basic Concepts
- Introduction
- Processing user interactions
- Nesting leaves
- Data Binding
- Tutorial
- Building a blog
- View Bridges
- Introduction
- The model
- Re-rendering
- Events
- Handling Children
- Controls
- Extending View Bridges
- Control Components
- What is a control?
- Text Controls
- TextBox
- TextArea
- PasswordTextBox
- Selection Controls
- The selection control pattern
- Standard Variants
- DropDown
- CheckSet
- RadioButtons
- SearchControl
- ModelSearchControl
- Attaching additional data
- Dynamically driving the available items
- File Uploads
- SimpleFileUpload
- Html5FileUpload
- Other
- Buttons
- Building your own control
- Application Components
- What is an application component?
- Pager
- Table
- SearchPanel
- Tabs
- Advanced Topics
- View Indexes
SearchControl
A SearchControl
presents a search interface which then returns a list of results from the server
to allow the user to make a selection from very large data sets.
Search controls require that items have attached data as the display method is traditionally a table of results and the columns of data are mapped to the values in the attached data.
SearchControl
is abstract and so must be extended in order to be configured correctly. This is because
knowledge of what columns to display in the results and how to apply the search cannot be automatically
determined.
<?php
namespace Rhubarb\Leaf\Controls\Common\Examples\SelectionControls;
use Rhubarb\Crown\String\StringTools;
use Rhubarb\Leaf\Controls\Common\SelectionControls\SearchControl\SearchControl;
class ExampleSearchControl extends SearchControl
{
protected function getResultColumns()
{
return ["FirstName", "Surname"];
}
protected function getCurrentlyAvailableSelectionItems()
{
$items = parent::getCurrentlyAvailableSelectionItems();
$filteredItems = [];
foreach($items as $item) {
if (StringTools::contains($item->label, $this->model->searchPhrase, false)) {
$filteredItems[] = $item;
}
}
return $filteredItems;
}
}
<?php
namespace Rhubarb\Leaf\Controls\Common\Examples\SelectionControls;
use Rhubarb\Leaf\Views\View;
class SearchControlExampleView extends View
{
protected function createSubLeaves()
{
$this->registerSubLeaf(
$control = new ExampleSearchControl("control")
);
$control->setSelectionItems(
[
[ 99, "John Smith", ["FirstName" => "John", "Surname" => "Smith" ]],
[ 98, "Jane Doe", ["FirstName" => "Jane", "Surname" => "Doe" ]],
ExampleContact::all()->addSort("FirstName")
]
);
}
protected function printViewContent()
{
print $this->leaves["control"];
}
public function getDeploymentPackage()
{
$package = parent::getDeploymentPackage();
$package->resourcesToDeploy[] = __DIR__.'/search.css';
return $package;
}
}
.results.drop-down {
background: white;
border: 1px solid #999;
}
.results-list tr td {
padding: 4px;
}
.results-list tr.active {
background: lightblue;
}
This basic implementation applies the search by overriding getCurrentlyAvailableSelectionItems()
and
filtering items that don't contain the search phrase ($this->model->searchPhrase
). This would not scale
however to large database searches.