Columns
Each column in the report output can be configured in a number of ways using the builder. Use the column method passing the name of the column and apply one of the following options :-- hide - hides the column from the report body.
- order - sets which column the data will appear in the report body table
- label - Alternative label to be placed in column headers and group sections
- columnwidth - How wide the column should be. Use css notation
- columnwidthpdf - How wide the column should be on a pdf report. Use css notation
- justify - Sets whether to left, right or centre justify the column value
Each column in the report output can be configured in a number of ways using the builder.
Use the column method passing the name of the column and apply one of the following options :-
Usage:
\Reportico\Engine\Builder\build()
->column(column :Name of column (based on name/alias from query results set))
->hide()
->order(order :The sequence of the column in the report output. Overrides the sequence from the query)
->label(label :The label to show in the column header)
->columnwidth(label :The width of the column in HTML output in CSS format eg 5px)
->justify(type [left|right|center])
In this example, we play with some basic display options for each column.
The justify method allows contents to be left, center or right justified. You can change the width of a column with the columnwidth() method and also use the order method to change the order of the columns in the output results.
Run Demo
<?php
require_once(__DIR__ .'/../vendor/autoload.php');
\Reportico\Engine\Builder::build()
->properties([ "bootstrap_preloaded" => true])
->datasource()->database("mysql:host=localhost; dbname=DATABASE NAME")->user("USER")->password("PASSWORD")
->title ("Product Stock")
->description ("Produces a list of our employees")
->sql ("
SELECT ProductID id, ProductName product, UnitsInStock in_stock, UnitsOnOrder on_order, companyname company, country, categoryname category
FROM northwind_products
join northwind_suppliers on northwind_products.supplierid = northwind_suppliers.supplierid
join northwind_categories on northwind_products.categoryid = northwind_categories.categoryid
WHERE 1 = 1
ORDER BY categoryname
")
->expression("total_stock")->sum("in_stock","category")
->group("category")
->throwPageBefore()
->trailer("total_stock")->below("in_stock")->label("Total")
->header("category")
->column("in_stock")->justify("right")->label("Right justified") // Right justify in stock column
->column("on_order")->justify("center")->label("Center justified") // Center justify in on order column
->column("company")->order(2)->label("Reordered") // Make the company column the second column
->column("country")->label("Country Renamed") // Change the header label for the country column
->column("company")->columnwidth("5cm")->label("Company 5cm wide") // Change the width of the company column to 100px ( its css so percentage works too )
->column("product")->columnwidth("500px")->label("Product 500px wide") // Change the width of the product column to 500px ( its css so percentage works too )
->execute();
?>