Input Sample
Result
TextBoxDemo = null
SelectDemo = null
DateTimePickerDemo = "2024-11-27 00:00:00"
DateRangePickerDemo = ["2024-11-27 00:00:00","2024-11-27 23:59:59"]
Select2Demo = null
MultipleSelect2Demo = null
CheckBoxListDemo = null
RadioListDemo = null
TextAreaDemo = null
This example shows you how to use input widgets to create dynamic dashboard. Inputs are special type of widget which receives inputs from user like text, click or menu selection and then transmits them to server to process. In above example, we show you the most used controls such as Text, Select, DateTimePicker etc.
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\Button;
class ButtonDemo extends Button
{
protected function actionSubmit($request, $response)
{
$this->sibling("Result")->update();
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\CheckBoxList;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \demo\AutoMaker;
class CheckBoxListDemo extends CheckBoxList
{
protected function dataSource()
{
return AutoMaker::table("customers")
->select("customerName")
->limit(5);
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
protected function fields()
{
return [
Text::create("customerName"),
];
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\DateRangePicker;
class DateRangePickerDemo extends DateRangePicker
{
protected function onCreated()
{
$this->defaultValue(DateRangePicker::today());
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\DateTimePicker;
class DateTimePickerDemo extends DateTimePicker
{
protected function onCreated()
{
$this->defaultValue(date("Y-m-d 00:00:00"));
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\Dashboard;
use \koolreport\dashboard\containers\Row;
use \koolreport\dashboard\containers\Panel;
use \koolreport\dashboard\Container;
use \koolreport\dashboard\inputs\Button;
use \koolreport\dashboard\containers\Html;
class InputsBoard extends Dashboard
{
protected function content()
{
return [
Row::create([
Panel::create()->type("primary")->header("<b>Input Sample</b>")->width(2/3)->sub([
Row::create([
[
Html::label("TextBox")->style("font-weight:bold"),
TextBoxDemo::create()
],
[
Html::label("Select")->style("font-weight:bold"),
SelectDemo::create()
]
]),
Row::create([
[
Html::label("DateTimePicker")->style("font-weight:bold"),
DateTimePickerDemo::create()
],
[
Html::label("DateRangePicker")->style("font-weight:bold"),
DateRangePickerDemo::create()
]
]),
Row::create([
[
Html::label("Select2")->style("font-weight:bold"),
Select2Demo::create()
],
[
Html::label("Multiple Select2")->style("font-weight:bold"),
MultipleSelect2Demo::create(),
]
]),
Row::create([
[
Html::label("CheckBoxList")->style("font-weight:bold"),
CheckBoxListDemo::create()
],
[
Html::label("RadioList")->style("font-weight:bold"),
RadioListDemo::create(),
]
]),
Row::create([
[
Html::label("TextArea")->style("font-weight:bold"),
TextAreaDemo::create(),
]
]),
ButtonDemo::create()
]),
Panel::create()->type("success")->header("<b>Result</b>")->width(1/3)->sub([
Result::create("Result")
])
]),
\demo\CodeDemo::create("
This example shows you how to use input widgets to create dynamic dashboard.
Inputs are special type of widget which receives inputs from user like text, click or menu selection
and then transmits them to server to process.
In above example, we show you the most used controls such as Text, Select, DateTimePicker etc.
")->raw(true)
];
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\Select2;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \demo\AutoMaker;
class MultipleSelect2Demo extends Select2
{
protected function onInit()
{
$this->multiple(true);
}
protected function dataSource()
{
return AutoMaker::table("customers")
->select("country")
->groupBy("country");
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
protected function fields()
{
return [
Text::create("country"),
];
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\RadioList;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \demo\AutoMaker;
class RadioListDemo extends RadioList
{
protected function dataSource()
{
return AutoMaker::table("customers")
->select("customerName","customerNumber")
->limit(5);
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
protected function fields()
{
return [
Number::create("customerNumber"),
Text::create("customerName"),
];
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\widgets\Text;
class Result extends Text
{
protected function onInit()
{
$this
->text(function(){
$html = "";
$list = [
"TextBoxDemo",
"SelectDemo",
"DateTimePickerDemo",
"DateRangePickerDemo",
"Select2Demo",
"MultipleSelect2Demo",
"CheckBoxListDemo",
"RadioListDemo",
"TextAreaDemo"
];
foreach($list as $name)
{
$value = json_encode($this->sibling($name)->value());
$value = htmlentities($value);
$html .= "<div><b>$name</b> = $value</div>";
}
return $html;
})
->asHtml(true);
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\Select2;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \demo\AutoMaker;
class Select2Demo extends Select2
{
protected function dataSource()
{
return AutoMaker::table("customers")
->select("country")
->groupBy("country");
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
protected function fields()
{
return [
Text::create("country"),
];
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\Select;
use \koolreport\dashboard\fields\Text;
use \koolreport\dashboard\fields\Number;
use \demo\AutoMaker;
class SelectDemo extends Select
{
protected function onCreated()
{
$this->defaultOption(["--"=>null]);
}
protected function dataSource()
{
return AutoMaker::table("customers")
->select("customerName")
->limit(5);
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
protected function fields()
{
return [
Text::create("customerName"),
];
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\TextArea;
class TextAreaDemo extends TextArea
{
protected function onCreated()
{
$this->placeHolder("TextArea");
}
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
}
<?php
namespace demo\inputs;
use \koolreport\dashboard\inputs\TextBox;
class TextBoxDemo extends TextBox
{
protected function actionChange($request, $response)
{
$this->sibling("Result")->update();
}
}