Column formatting

Column formatting

Change the width of a column

You can change the width of a column of a table using the 'columnWidth' parameter. Simply specify the width of the column in pixels using this option

$table->addColumn("sales", "Sales Amount", array(
    "columnWidth" => 140
));

Change the way numbers are displayed

You can configure how number are formatted and displayed in the table using the standard Number Formatting Parameters. However, you need to also specify that the column's data type is a number for this.

$table->addColumn("sales", "Sales Amount", array(
    "dataType" => "number",
    "numberPrefix" => "$"
));

<?php

class SampleDashboard extends StandaloneDashboard { public function buildDashboard () { $table = new TableComponent('table1'); $table->setCaption("Regional Sales"); $table->setDimensions (4, 4); $table->setRowsPerPage (8); $table->addColumn('zone', "Zone"); $table->addColumn('name', "Store Name"); $table->addColumn('sale', "Sales Amount", array( "dataType" => "number", "numberPrefix" => "$ ", "textAlign" => "center" ));

    $data = array(
      array("zone" => "North", "name" => "Northern Stores", "sale" => 4000),
      array("zone" => "South", "name" => "Southern Stores", "sale" => 4500)
    );

    $table->addMultipleRows($data);

    $this->addComponent ($table);
}

}

$db = new SampleDashboard(); $db->renderStandalone();