Adding data to the table

You can add a table component to the dashboard by creating an intance of the TableComponent class in your dashboard code.

$table = new TableComponent ();
$table->setCaption ("Regional Sales");
$table->setDimensions(4, 4);

// Configure the table

$this->addComponent($table);

Add data to the table

For adding the data, there are two steps:

  1. Add one or more column definitions to the table.
  2. Add rows of data to the table.

Adding columns

To add columns to the table, you can use the addColumn function. The first parameter to the addColumn function is a unique string key for the column.

$table->addColumn ('storeName', "Store Name");
$table->addColumn ('salesAmount', "Sales");

Adding rows

Let's say a table has 3 columns like this:

$table = new TableComponent ("table1");
$table->addColumn ('zone', "Store Zone Name");
$table->addColumn ('name', "Store Name");
$table->addColumn ('sale', "Sales amount");

You can add a row by passing a JavaScript object like this:

$table->addRow (array("zone" => "North", "name" => "Northern Stores", "saleAmount" => 5000));

Add multiple rows at once

$data = array(
    array("zoneName" => "North", "name" => "Northern Stores", "sale" => 4000),
    array("zoneName" => "South", "name" => "Southern Stores", "sale" => 4500)
);
$table->addMultipleRows ($data);

<?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");

    $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();