### PdoDataSource Report Setup Example
Source: https://www.koolreport.com/docs/datasources/pdodatasource
Example demonstrating how to configure and use PdoDataSource in a KoolReport setup function to query and process data.
```php
array(
"mysql_datasource"=>array(
"connectionString"=>"mysql:host=localhost;dbname=mysql_databases",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
),
)
);
}
public function setup()
{
$this->src('mysql_datasource')
->query("SELECT * FROM tblPurchase where status=:status")
->params(array(":status"=>"completed"))
->pipe(..)
->pipe(..)
->pipe($this->dataStore('purchase_summary'));
}
}
```
--------------------------------
### Project Folder Structure
Source: https://www.koolreport.com/docs/dashboard/quick_start
This illustrates the expected file and directory structure for the Quick Start project after setup.
```text
quick_start
├── vendor
│ └── koolreport
├── composer.json
├── index.php
├── App.php
├── PaymentBoard.php
├── PaymentTable.php
└── AutoMaker.php
```
--------------------------------
### Donut Chart Example
Source: https://www.koolreport.com/docs/morris_chart/overview
Create a Donut chart by specifying the data store, columns, and options. This example shows basic setup for a Donut chart.
```php
$this->dataStore('sale'),
"columns"=>array(
'month',
'income'=>array(
"label"=>"Income",
"type"=>"number",
"prefix"=>"$",
),
'expense'=>array(
"label"=>"Income",
"type"=>"number",
"prefix"=>"$",
)
),
"options"=>array(
//Extra settings for Area Chart
),
));
?>
```
--------------------------------
### Directory Structure Example
Source: https://www.koolreport.com/docs/appstack/overview
Illustrates the expected directory structure after copying the AppStack folder into the KoolReport directory when installing via a zip file.
```text
koolreport
├── core
├── appstack
```
--------------------------------
### Run the Report
Source: https://www.koolreport.com/docs/architecture/life_cycle
Execute the report after initiation to start the data pumping and processing. This command triggers the data flow through the defined setup.
```php
$report = new SaleReport(array(
"startDate"=>"2017-01-01",
"endDate"=>"2018-01-01"
));
//Run report
$report->run();
```
--------------------------------
### Directory Structure Example
Source: https://www.koolreport.com/docs/codegen/installation
Illustrates the basic directory structure for KoolReport Codegen after manual installation.
```text
www
├── codegen
│ ├── public
│ ├── tmp
```
--------------------------------
### Complete Parameter Binding Setup
Source: https://www.koolreport.com/docs/inputs/first_things
This snippet shows the complete setup for parameter binding, including traits, default values, and parameter-to-input mapping.
```php
array('2017-07-01','2017-07-31'),
"customer"=>"John Lennon",
);
}
protected function bindParamsToInputs()
{
return array(
"dateRange"=>"dateRangeInput",
"customer"=>"customerInput",
);
}
...
}
```
--------------------------------
### Setup Data Processing Pipeline
Source: https://www.koolreport.com/docs/architecture/life_cycle
Define the data flow in the setup() method by specifying data sources, transformations, and data stores.
```php
protected function setup()
{
$this->src('sale')
->query("select customerName, dollar_sales from orders")
->pipe(new Group(
"by"=>"customerName"
"sum"=>"dollar_sales"
))
->pipe($this->dataStore("sales_by_customer"));
}
```
--------------------------------
### Basic GaugeCard Example
Source: https://www.koolreport.com/docs/amazing/gaugecard
A fundamental example demonstrating how to create a GaugeCard with a title, value, preset, base value, and formatting for the value.
```php
"Revenue",
"value"=>7500,
"preset"=>"success",
"baseValue"=>10000,
"minValue" => 0,
"maxValue" => 100,
"showValue" => true,
"showBaseValue" => true,
"format"=>array(
"value"=>array(
"prefix"=>"$"
)
),
));
?>
```
--------------------------------
### Setup Report Data Flow
Source: https://www.koolreport.com/docs/tutorials/get_started_with_koolreport
Define the setup() method in your report class to establish the data processing pipeline. This involves selecting a data source, executing a SQL query, and piping the results to a named data store.
```php
src("automaker")
->query(
"SELECT customers.customerName, sum(payments.amount) as saleamount\n FROM payments\n JOIN customers ON customers.customerNumber = payments.customerNumber\n GROUP BY customers.customerName\n LIMIT 10"
)
->pipe($this->dataStore("result"));
}
}
```
--------------------------------
### Basic Table Widget Setup
Source: https://www.koolreport.com/docs/dashboard/widgets/table
This snippet demonstrates the basic setup of a Table widget, including defining the data source and specifying the fields to be displayed with their respective types and formatting.
```php
select("id","customerName","amount");
}
protected function fields()
{
return [
Number::create("id"),
Text::create("customerName"),
Currency::create("amount")->USD()->symbol()
];
}
}
```
--------------------------------
### Application Integration Example
Source: https://www.koolreport.com/docs/dashboard/customboard
This PHP code shows how to integrate the 'OfficeBoard' into the application's sidebar.
```php
class App extends Application
{
...
protected function sidebar()
{
return [
"Office List"=>OfficeBoard::create()
];
}
}
```
--------------------------------
### Manual Download Example Directory Structure
Source: https://www.koolreport.com/docs/installation
This illustrates the expected directory structure after unzipping the KoolReport & Examples package into your web server's document root (htdocs).
```bash
htdocs
├── testing
│ ├── koolreport
│ └── examples
```
--------------------------------
### PieChart Data Source and Fields Example
Source: https://www.koolreport.com/docs/dashboard/widgets/d3
Example of setting up a PieChart with a data source and defining fields. This snippet shows how to fetch and format data for visualization.
```php
leftJoin("customers","customers.customerNumber","=","payments.customerNumber")
->groupBy("payments.customerNumber")
->select("customers.customerName")
->sum("amount")->alias("total")
->orderBy("total","desc")
->limit(5);
}
protected function fields()
{
return [
Text::create("customerName"),
Currency::create("total")
->USD()->symbol()
->decimals(0),
];
}
}
```
--------------------------------
### Basic Category Metric Setup
Source: https://www.koolreport.com/docs/dashboard/metrics
This snippet demonstrates the basic setup for a Category metric, summing 'quantityInStock' by 'productLine'. Ensure you have the necessary KoolReport components imported.
```php
group(Text::create("productLine")),
$this->sum(Number::create("quantityInStock"))
];
}
}
```
--------------------------------
### Index View Example
Source: https://www.koolreport.com/docs/dashboard/customboard
This is an example of a view file 'index.view.php' that displays office data using a KoolReport Table widget.
```php
//index.view.php
My office list
$this->params()["offices"];
])
?>
```
--------------------------------
### Accessing KoolReport Examples via Localhost
Source: https://www.koolreport.com/docs/installation
Once the examples are set up in your htdocs, you can access them through your web browser using this URL structure.
```bash
https://localhost/testing/examples
```
--------------------------------
### MySQL Connection String Example
Source: https://www.koolreport.com/docs/datasources/pdodatasource
Example of a PDO connection string for MySQL databases.
```php
'mysql:host=127.0.0.1:3306;dbname=automaker'
```
--------------------------------
### Basic ChartCard Example
Source: https://www.koolreport.com/docs/amazing/chartcard
A fundamental example of creating a ChartCard with a title, value, preset appearance, and chart data source.
```php
"Member Online",
"value"=>56000,
"preset"=>"primary",
"chart"=>array(
"dataSource"=> $this->dataStore("online_by_day),
),
"cssClass"=>array(
"icon"=>"icon-people"
)
));
?>
```
--------------------------------
### SQL Server Connection String Example
Source: https://www.koolreport.com/docs/datasources/pdodatasource
Example of a PDO connection string for SQL Server databases.
```php
'sqlsrv:server=localhost;Database=automaker'
```
--------------------------------
### Select Input Configuration
Source: https://www.koolreport.com/docs/dashboard/inputs
Sets up a Select input with default options, CSS styling, and size. This example demonstrates how to configure a multi-select dropdown.
```php
defaultOption(0) //Select the first office
->cssStyle("margin-left:10px")
->cssClass("form-control")
->size("lg");
}
//Provide datasource
protected function dataSource()
{
return AutoMaker::table("offices")
->select("officeCode","addressLine1");
}
//Provide list of fields to act as value and text for MultiSelect
protected function fields()
{
return [
Number::create("officeCode"),
Text::create("addressLine1")
];
}
//Update the EmployeeTable when user select values
protected function actionChange($request, $response)
{
$this->sibling("EmployeeTable")->update();
}
}
```
--------------------------------
### PostgreSQL Connection String Example
Source: https://www.koolreport.com/docs/datasources/pdodatasource
Example of a PDO connection string for PostgreSQL databases.
```php
'pgsql:host=localhost;dbname=automaker'
```
--------------------------------
### Directory Structure for Zip Installation
Source: https://www.koolreport.com/docs/sparklines/overview
Illustrates the expected directory structure after manually installing the Sparklines library by unzipping the downloaded file into the KoolReport folder.
```text
koolreport
├── core
├── sparklines
```
--------------------------------
### Apply Statistics Measures in Report Setup
Source: https://www.koolreport.com/docs/statistics/overview
Configure the Statistics process in your report's setup method to calculate various statistical measures for specified columns. Use '{{all}}' to apply to all columns.
```php
src('sales')
->pipe(new Statistics(array(
'min' => array('2003'),
'max' => array('2003'),
'mean' => array('2003', '2004'),
'median' => array('2003', '2004', '{{all}}'),
'lowerQuartile' => array('2005'),
'upperQuartile' => array('2005'),
'meanDeviation' => array('{{all}}'),
'stdDeviation' => array('{{all}}'),
'percentile_10' => array('{{all}}'),
'percentile_90' => array('{{all}}'),
)))
->pipe($this->dataStore('salesYearMonthStatistics'));
}
}
```
--------------------------------
### Table Widget with DataStore
Source: https://www.koolreport.com/docs/data_visualization/widget
Example of creating a Table widget using a DataStore as its data source.
```php
$this->dataStore("mydata"),
...
))
?>
```
--------------------------------
### Directory Structure for Excel Package
Source: https://www.koolreport.com/docs/excel/overview
Illustrates the expected directory structure after manually installing the Excel package.
```text
koolreport
├── core
├── excel
```
--------------------------------
### Bar Chart Example
Source: https://www.koolreport.com/docs/morris_chart/overview
Example of creating a Bar chart with sales, cost, and profit data. Includes column definitions with labels, types, prefixes, and custom hover templates.
```php
Bar::create(array(
"dataSource"=>$category_amount,
"columns"=>array(
"category",
"sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
"cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
"profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
),
"options" => array(...),
"colorScheme" => array(...),
"hoverTitleTemplate" => "Title: {titleValue}
",
"hoverItemTemplate" => "
{itemName}:
{itemValue}
",
));
```
--------------------------------
### Advanced Panel Configuration with Menu
Source: https://www.koolreport.com/docs/dashboard/containers
This example demonstrates a Panel with advanced configurations including a header, type, menu icon, and a dynamic menu with various actions like onClick events, links, and disabled items.
```php
use koolreportdashboardDashboard;
use koolreportdashboardcontainersPanel;
use koolreportdashboardmenuMenuItem;
class SaleBoard extends Dashboard
{
protected function content()
{
return [
Panel::create()
->header("Panel title")
->type("info")
->sub([
SaleColumnChart::create()
])
->menuIcon("fas fa-chevron-circle-down")
->menu([
"Show details"=>MenuItem::create()
->onClick(Client::widget("SaleColumnChart")->showDetail()),
"Simple link"=>MenuItem::create()
->href("https://www.anywebsite.com")
->target("_blank"),
"With Icon and Badge"=>MenuItem::create()
->href("https://www.example.com")
->icon("fa fa-book")
->badge(["NEW","danger"]),
"Execute javascript"=>MenuItem::create()
->onClick("alert('hola')"),
"Load Dashboard"=>MenuItem::create()
->onClick(Client::dashboard("MarketingBoard")->load()),
"Disabled Item"=>MenuItem::create()->disabled(true),
])
];
}
}
```
--------------------------------
### Get Top N Rows from DataStore
Source: https://www.koolreport.com/docs/datastore/overview
Retrieves a specified number of top rows from the DataStore. Can also specify an offset to start from.
```php
$store = $this->dataStore('sales')->top(20); // Top 20 rows
$store = $this->dataStore('sales')->top(20,10); // Row from 10-30
```
--------------------------------
### slice()
Source: https://www.koolreport.com/docs/datastore/overview
Gets a slice of data starting from a specified offset. If a length is provided, it specifies the number of rows to retrieve; otherwise, all rows after the offset are returned.
```APIDOC
## slice()
### Description
Gets a slice of data starting from a specified offset. If a length is provided, it specifies the number of rows to retrieve; otherwise, all rows after the offset are returned.
### Method
`slice(integer $offset[, integer $length=null])`
### Parameters
#### Path Parameters
- **$offset** (integer) - Required - Starting row to get offset
- **$length** (integer) - Optional - Number of rows to take, if not specified, all rows after $offset will be returned.
### Request Example
```php
$store = $this->dataStore('sales')->slice(50); // Get rows from 50 to the end
$store = $this->dataStore('sales')->slice(10,20); // Get rows from 10 to 30
```
```
--------------------------------
### Apply Transpose2 Process in KoolReport PHP
Source: https://www.koolreport.com/docs/processes/transpose2
This example shows how to integrate the Transpose2 process into a KoolReport report's setup method, piping data to it for transformation.
```php
pipe(new Transpose2())
...
}
}
```
--------------------------------
### Initiate and Render Report
Source: https://www.koolreport.com/docs/tutorials/get_started_with_koolreport
Create an index.php file to run the report. This involves including the autoloader and the report class, instantiating the report, running it, and rendering the output.
```php
run()->render();
```
--------------------------------
### Accessing Dashboard Instance in View
Source: https://www.koolreport.com/docs/dashboard/customboard
This example shows how to get a reference to the dashboard instance within a view file using '$this->board()' to call its methods.
```php
board()->getWelcome(); ?>
```
--------------------------------
### Create Bootstrap File
Source: https://www.koolreport.com/docs/dashboard/admin/overview
This snippet shows how to create the main index file to initiate the Admin Panel application.
```php
debugMode(true)->run();
```
--------------------------------
### Configure ApcCache for Widget Demand
Source: https://www.koolreport.com/docs/dashboard/caching
This example shows how to configure ApcCache for caching on a widget's demand. No specific TTL or server configuration is needed for this basic setup.
```php
use \koolreport\dashboard\caching\ApcCache;
...
// Cache on widget demand
protected function cache()
{
return ApcCache::create();
}
```
--------------------------------
### Configure MemCache with Servers
Source: https://www.koolreport.com/docs/dashboard/caching
This example shows how to set up MemCache with a list of servers, specifying their host and port. This is used for caching on a widget's demand.
```php
use \koolreport\dashboard\caching\MemCache;
...
// Cache on widget demand
protected function cache()
{
return MemCache::create()
->servers([
"localhost"=>3434, //"host"=>port
"1.233.222.24"=>1212
]);
}
```
--------------------------------
### Setup Eloquent Datasource in KoolReport
Source: https://www.koolreport.com/docs/laravel/overview
Configure KoolReport to use Laravel's Eloquent ORM as a data source. Ensure the Eloquent query does not end with a get() method.
```php
class MyReport extends \koolreport\KoolReport
{
use \koolreport\laravel\Friendship;
function settings()
{
return array(
"dataSources"=>array(
"elo"=>array(
"class"=>'\koolreport\laravel\Eloquent', // This is important
)
)
);
}
function setup()
{
//Now you can use Eloquent inside query() like you normally do
$this->src("elo")->query(
App\Flight::where('active', 1)
->orderBy('name', 'desc')
->take(10)
)
->pipe($this->dataStore("flight"));
}
}
```
--------------------------------
### Handle Input Change Event
Source: https://www.koolreport.com/docs/dashboard/inputs
This example shows how to catch the 'change' event from a Select input component and trigger an update on another widget. It demonstrates server-side event handling for user interactions.
```php
select("customerNumber","customerName");
}
//By adding this function, you will catch event change of Select
protected function actionChange($request, $response)
{
//This code will be execute when user select a customer
//It will ask PaymentTable to update
$this->dashboard()->widget("PaymentTable")->update();
}
}
\PaymentTable.php ---------------------
use \koolreport\dashboard\widgets\Table;
class PaymentTable extends Table
{
protected function dataSource()
{
// PaymentTable will get the customerNumber from CustomerSelect widget
// and perform query
$customerNumber = $this->dashboard()->widget("CustomerSelect")->value();
return AutoMaker::table("payments")
->where("customerNumber",$customerNumber);
}
}
```
--------------------------------
### Select2 Input Configuration
Source: https://www.koolreport.com/docs/dashboard/inputs
Configures a Select2 input with placeholder, multiple selection option, and CSS styling. This example shows how to set up a searchable dropdown.
```php
defaultOption(0) //Select the first office
->cssStyle("margin-left:10px")
->cssClass("form-control")
->size("lg")
->multiple(false)
->placeHolder("Select list of offices");
}
//Provide datasource
protected function dataSource()
{
return AutoMaker::table("offices")
->select("officeCode","addressLine1");
}
//Provide list of fields to act as value and text for MultiSelect
protected function fields()
{
return [
Number::create("officeCode"),
Text::create("addressLine1")
];
}
//Update the EmployeeTable when user select values
protected function actionChange($request, $response)
{
$this->sibling("EmployeeTable")->update();
}
}
```
--------------------------------
### Get Top Percentage of Rows from DataStore
Source: https://www.koolreport.com/docs/datastore/overview
Retrieves a specified percentage of top rows from the DataStore. For example, 25% of 50 rows will return the top 12 or 13 rows.
```php
$store = $this->dataStore('sales')->topByPercent(25); // Top 25% of rows
```
--------------------------------
### KoolReport CheckBox Widget Configuration
Source: https://www.koolreport.com/docs/dashboard/inputs
Configure a CheckBox widget with text, inline display, change event handlers, and CSS styling. This example demonstrates setting various properties for a single checkbox.
```php
CheckBox::create("checkboxAutoUpdate")
->text("Auto Update")
->inline(false)
->onChange("console.log('do something at client-side')")
->action("change",function($request, $response){
//Do something at server-side
})
->cssStyle("margin-left:5px;")
->cssClass("my-checkbox-css-class")
```
--------------------------------
### Handling Select Event in DataTables
Source: https://www.koolreport.com/docs/datagrid/datatables
Configure client-side events for DataTables using the `clientEvents` property. This example shows how to handle the 'select' event to get the ID of selected items.
```php
array(
"select"=>"function(e,dt,type,indexes){
var data = dt.rows( indexes ).data().pluck( 'id' );
// do something with the ID of the selected items
}"
)
));
?>
```
--------------------------------
### MySQLDataSource Configuration and Usage Example
Source: https://www.koolreport.com/docs/datasources/mysqldatasource
This snippet shows how to configure MySQLDataSource in KoolReport's settings and use its query and params methods in the setup function to fetch data from a MySQL database.
```php
array(
"automaker"=>array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'automaker',
'charset' => 'utf8',
'class' => "\koolreport\datasources\MySQLDataSource"
),
)
);
}
public function setup()
{
$this->src('automaker')
->query("SELECT * FROM tblPurchase where status=:status")
->params(array(":status"=>"completed"))
->pipe(..)
->pipe(..)
->pipe($this->dataStore('purchase_summary'));
}
}
```
--------------------------------
### SQLSRVDataSource Configuration and Query Example
Source: https://www.koolreport.com/docs/datasources/sqlsrvdatasource
This snippet demonstrates how to configure the SQLSRVDataSource in KoolReport's settings and use it to execute a parameterized query in the setup function. Ensure your SQL Server connection details are correctly provided.
```php
array(
"sqlserver"=>array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'automaker',
'charset' => 'utf8',
'class' => "\koolreport\datasources\SQLSRVDataSource"
),
)
);
}
public function setup()
{
$this->src('sqlserver')
->query("SELECT * FROM tblPurchase where status=:status")
->params(array(":status"=>"completed"))
->pipe(..)
->pipe(..)
->pipe($this->dataStore('purchase_summary'));
}
}
```
--------------------------------
### Basic Line Chart Setup
Source: https://www.koolreport.com/docs/chartjs/line_chart
This snippet shows the minimum configuration required to create a LineChart. It uses two columns from the data source for labeling the x-axis and representing data series.
```php
"Sale vs Cost",
"dataSource"=>$this->dataStore('month_sales'),
"columns"=>array(
"month",
"sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
"cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
)
));
```
--------------------------------
### Install KoolReport MongoDB Package via Composer
Source: https://www.koolreport.com/docs/mongodb/overview
Use Composer to install the KoolReport MongoDB package. Ensure Composer is installed and configured in your project.
```bash
composer require koolreport/mongodb
```
--------------------------------
### Install KoolReport Core via Composer
Source: https://www.koolreport.com/docs/installation
Use this command to install the core KoolReport library using Composer. Ensure Composer is installed and accessible in your environment.
```bash
composer require koolreport/core
```
--------------------------------
### Line Chart Example
Source: https://www.koolreport.com/docs/morris_chart/overview
Create a Line chart by specifying the data store, columns with labels and formatting, and chart options.
```php
$this->dataStore('sale'),
"columns"=>array(
'month',
'income'=>array(
"label"=>"Income",
"type"=>"number",
"prefix"=>"$",
),
'expense'=>array(
"label"=>"Income",
"type"=>"number",
"prefix"=>"$",
)
),
"options"=>array(
//Extra settings for Line Chart
),
));
?>
```
--------------------------------
### Install Yii2 Package via Composer
Source: https://www.koolreport.com/docs/yii2/overview
Install the koolreport/yii2 package using Composer.
```bash
composer require koolreport/yii2
```
--------------------------------
### Install KoolReport Laravel Package
Source: https://www.koolreport.com/docs/laravel/overview
Install the KoolReport Laravel package using Composer.
```bash
composer require koolreport/laravel
```
--------------------------------
### Handling OnBeforeSetup Event
Source: https://www.koolreport.com/docs/architecture/events
This event occurs just before the data processing tree is set up. Returning `true` permits the setup process, while `false` can halt it. Ideal for pre-setup validation or configuration checks.
```php
protected function OnBeforeSetup()
{
echo "About to setup data process tree";
return true;
}
```
--------------------------------
### SelectFilter Options Examples
Source: https://www.koolreport.com/docs/dashboard/admin/filters
Demonstrates different ways to provide options for a SelectFilter, including simple arrays, associative arrays, and PDOSource.
```php
protected function options()
{
//Simple array form
return [
"United State",
"Germany",
"France"
];
//Associate array "text"=>"value"
return [
"text"=>"value",
"United State"=>"usa",
"Germany"=>"germany",
]
//From PDOSource
return AutoMaker::table("customers")
->select("country")
->distinct();
}
```
--------------------------------
### Composer Installation Repositories
Source: https://www.koolreport.com/docs/drilldown/overview
Add this to your composer.json to specify the KoolReport repository for package installation.
```json
{
"repositories":[
{"type":"composer","url":"https://repo.koolreport.com"}
],
"require":{
"koolreport/drilldown":"*",
...
}
}
```
--------------------------------
### MongoDB Connection String Example
Source: https://www.koolreport.com/docs/datasources/pdodatasource
Example of a PDO connection string for MongoDB databases.
```php
'mongodb://localhost:27017'
```
--------------------------------
### Initiate Report with Parameters
Source: https://www.koolreport.com/docs/architecture/life_cycle
Create a new report object and pass initial parameters like start and end dates.
```php
$report = new SaleReport(array(
"startDate"=>"2017-01-01",
"endDate"=>"2018-01-01"
));
```
--------------------------------
### Oracle Connection String Example
Source: https://www.koolreport.com/docs/datasources/pdodatasource
Example of a PDO connection string for Oracle databases.
```php
'oci:dbname=//localhost:1521/ORCLCDB'
```
--------------------------------
### Create a Table Widget
Source: https://www.koolreport.com/docs/data_visualization/widget
Demonstrates the basic creation of a Table widget, specifying its data source and columns. Requires importing the Table class.
```php
Sale Report
$this->dataStore('sales'),
"columns"=>array("product","sale_amount")
));
?>
```
--------------------------------
### TextBox with Properties and Client Events
Source: https://www.koolreport.com/docs/inputs/textbox
This example demonstrates configuring a TextBox with a value, custom HTML attributes, and a client-side focus event.
```php
"customer",
"value"=>"John Lennon",
"attributes"=>array(
"class"=>"form-control"
),
"clientEvents"=>array(
"focus"=>"function(){
console.log('focus');
}",
)
]);
?>
```
--------------------------------
### Install CloudExport via Composer
Source: https://www.koolreport.com/docs/cloudexport/overview
Use this command to install the CloudExport package using Composer.
```bash
composer require koolreport\/cloudexport
```
--------------------------------
### Install Bootstrap4 via Composer
Source: https://www.koolreport.com/docs/bootstrap4/overview
Install the Bootstrap4 package using Composer for your KoolReport project.
```bash
composer require koolreport/bootstrap4
```
--------------------------------
### Setting Custom View Folder
Source: https://www.koolreport.com/docs/dashboard/customboard
This example demonstrates how to set a custom view folder for a CustomBoard instance using the 'viewFolder' method within the 'onCreated' lifecycle method.
```php
use \koolreport\dashboard\CustomBoard;
class MyDashboard extends CustomBoard
{
protected function onCreated()
{
//From now, the CustomBoadrd will look for view file inside "views" folder.
$this->viewFolder(__DIR__."/views");
}
}
```
--------------------------------
### Install Bootstrap3 via Composer
Source: https://www.koolreport.com/docs/bootstrap3/overview
Use Composer to install the Bootstrap3 package for your KoolReport project.
```bash
composer require koolreport/bootstrap3
```
--------------------------------
### Composer Installation Repositories
Source: https://www.koolreport.com/docs/apexcharts/overview
Add these repositories to your composer.json file to enable installation of the ApexCharts package.
```json
{
"repositories":[
{"type":"composer","url":"https://repo.koolreport.com"}
],
"require":{
"koolreport/apexcharts":"*",
...
}
}
```
--------------------------------
### Basic BarChart Example
Source: https://www.koolreport.com/docs/chartjs/bar_chart
This snippet demonstrates the basic creation of a BarChart using a DataStore. It specifies the title, data source, and columns to be displayed, including custom labels and formatting for numerical data.
```php
"Sale Report",
"dataSource"=>$this->dataStore('sales')
"columns"=>array(
"category",
"sale"=>array("label"=>"Sale","type"=>"number","prefix"=>"$"),
"cost"=>array("label"=>"Cost","type"=>"number","prefix"=>"$"),
"profit"=>array("label"=>"Profit","type"=>"number","prefix"=>"$"),
)
));
```
--------------------------------
### Install QueryBuilder via Composer
Source: https://www.koolreport.com/docs/querybuilder/overview
Install the QueryBuilder package using Composer by running the command in your terminal.
```bash
composer require koolreport/querybuilder
```
--------------------------------
### Load Dashboard with Parameters from Client
Source: https://www.koolreport.com/docs/dashboard/dashboard
Initiate loading a dashboard from the client-side using the `Client` class and specify initial parameters for it.
```php
use \koolreport\dashboard\Client;
class ExampleDashboard extends Dashboard
{
protected function content() {
return [
Button::create()
->text("Load dashboard with params")
->onClick(Client::dashboard("OtherBoard")->load(["key"=>"value"]))
];
}
}
```
--------------------------------
### Rendering View with Parameters (Naming Section)
Source: https://www.koolreport.com/docs/dashboard/customboard
Shows how to render a view file named 'bobby.view.php' and pass parameters to it.
```php
$this->renderView("bobby"[
"age"=>37
]); //Render view with parameters
```
--------------------------------
### Composer Installation Configuration
Source: https://www.koolreport.com/docs/datagrid/overview
Configure your composer.json file to include the KoolReport repository and specify the DataGrid package for installation.
```json
{
"repositories":[
{"type":"composer","url":"https://repo.koolreport.com"}
],
"require":{
"koolreport/datagrid":"*",
...
}
}
```
--------------------------------
### Install Instant Package with Composer
Source: https://www.koolreport.com/docs/instant/overview
Use Composer to install the KoolReport Instant package. This is the recommended method for managing dependencies.
```bash
composer require koolreport/instant
```
--------------------------------
### Install Puppeteer with NPM
Source: https://www.koolreport.com/docs/export/overview
Run this command in the export package directory to install Puppeteer for Chrome headless PDF export.
```bash
npm i puppeteer
```
--------------------------------
### Application Event Handling Example
Source: https://www.koolreport.com/docs/dashboard/events
Demonstrates how to handle application-level events like 'onCreated', 'onError', and 'onRendering' in a custom Application class.
```php
title("Dashboard");
}
protected function onError($exception)
{
Log::error("Something happens" . $exception->getMessage());
}
protected function onRendering()
{
if(/*something wrong*/)
{
return false; // Not allowed to render
}
return true; // Allow to render
}
}
```
--------------------------------
### Category Metric with ShowTop
Source: https://www.koolreport.com/docs/dashboard/metrics
This example shows how to limit the displayed categories to the top 3 using the `showTop()` method. This is useful when dealing with a large number of categories.
```php
protected function fields()
{
return [
$this->group(
Text::create("productLine")
)->showTop(3),
$this->sum(Number::create("quantityInStock"))
];
}
```
--------------------------------
### Directory Structure for Zip Installation
Source: https://www.koolreport.com/docs/export/overview
This shows the expected directory structure after installing the export package by downloading a zip file.
```text
koolreport
├── core
├── export
```
--------------------------------
### Install CleanData Package
Source: https://www.koolreport.com/docs/cleandata/overview
Install the CleanData package using Composer. This is the recommended method for integrating the package into your KoolReport project.
```bash
composer require koolreport/cleandata
```
--------------------------------
### Basic Donut Chart Example
Source: https://www.koolreport.com/docs/google_charts/donut_chart
Generates a basic donut chart with categories and costs. Ensure the 'sale_of_category' datastore is available.
```php
"Sale Of Category",
"dataSource"=>$this->dataStore('sale_of_category'),
"columns"=>array(
"category",
"cost"=>array(
"type"=>"number",
"prefix"=>"$",
)
)
));
?>
```
--------------------------------
### Dashboard Event Handling Example
Source: https://www.koolreport.com/docs/dashboard/events
Illustrates how to define event handlers for 'onCreated', 'onInit', and 'onError' in a custom Dashboard class.
```php
title("My Dashboard");
}
protected function onInit()
{
//Anything you set here will be the last before dashboard is going to be rendered.
$this->title("My Dashboard");
}
protected function onError($exception)
{
//Error happens inside dashboard
Log::error("Something went wrong");
}
}
```
--------------------------------
### Install Bootstrap5 Package via Composer
Source: https://www.koolreport.com/docs/bootstrap5/overview
Install the Bootstrap5 package using Composer for easy integration into your KoolReport project.
```bash
composer require koolreport/bootstrap5
```
--------------------------------
### TextArea with Properties and Client Events
Source: https://www.koolreport.com/docs/inputs/textarea
This example demonstrates how to configure a TextArea with a specific value, custom attributes like rows and class, and a client-side focus event.
```php
"customer",
"value"=>"John Lennon",
"attributes"=>array(
"rows"=>5,
"class"=>"form-control"
),
"clientEvents"=>array(
"focus"=>"function(){
console.log('focus');
}",
)
});
?>
```
--------------------------------
### Custom DataSource Class Structure
Source: https://www.koolreport.com/docs/extending/datasource
Extend the \koolreport\core\DataSource class to create a new data source. Implement onInit() for initialization and start() for data piping. The start() method requires sending meta data, starting the input, sending data rows, and ending the input.
```php
class MyNewDataSource extend \koolreport\core\DataSource
{
/**
* Be called when datasource is initiated
*
* @return null
*/
protected function onInit()
{
// This method is called when datasource is initated
// You may get all the parameters of datasource through $this->params
}
/**
* Start piping data
*
* @return null
*/
public function start()
{
// Everything start with sending meta data
$this->sendMeta($metaData,$this);
//Call startInput() to begin data pipe
$this->startInput(null);
//Loop through your data and use next() to send row by row of data
foreach($data as $row)
{
$this->next($row);
}
//At the end, call endInput() to close the data pipe
$this->endInput(null);
}
}
```
--------------------------------
### Rendering View by Name
Source: https://www.koolreport.com/docs/dashboard/customboard
Demonstrates how to render a view file named 'bobby.view.php' without passing any parameters.
```php
$this->renderView("bobby"); // Render view without parameter
```