SwatTableView Demo

 FruitMakes JamMakes PieHarvest DateCost per kg
Apple
 YesSeptember$0.50
Orange
  April$0.75
Strawberry
Yes July$0.60

These actions are for demonstration purposes only.

The actions do not do anything as this page is not connected to a database.
Actions apply to checked items.

SwatML for this demo:


<?xml version="1.0" standalone="no"?>
<!DOCTYPE swatml SYSTEM "http://swat.silverorange.com/swatml1.dtd">
<swatml>
  <widget class="SwatForm" id="my_form">

    <widget class="SwatTableView" id="table_view">
      <object class="SwatTableViewCheckboxColumn" id="checkbox">
        <object class="SwatCheckboxCellRenderer" id="items">
          <property name="value" type="data">title</property>
        </object>
      </object>
      <object class="SwatTableViewColumn">
        <property name="title">Fruit</property>
        <object class="SwatImageCellRenderer">
          <property name="image" type="data">image</property>
          <property name="width" type="data">image_width</property>
          <property name="height" type="data">image_height</property>
        </object>
        <object class="SwatTextCellRenderer">
          <property name="text" type="data">title</property>
        </object>
      </object>
      <object class="SwatTableViewColumn">
        <property name="title">Makes Jam</property>
        <object class="SwatBooleanCellRenderer">
          <property name="value" type="data">makes_jam</property>
        </object>
      </object>
      <object class="SwatTableViewColumn">
        <property name="title">Makes Pie</property>
        <object class="SwatBooleanCellRenderer">
          <property name="value" type="data">makes_pie</property>
        </object>
      </object>
      <object class="SwatTableViewColumn">
        <property name="title">Harvest Date</property>
        <object class="SwatDateCellRenderer">
          <property name="date" type="data">harvest_date</property>
          <property name="format" type="string">%B</property>
        </object>
      </object>
      <object class="SwatTableViewColumn">
        <property name="title">Cost per kg</property>
        <object class="SwatMoneyCellRenderer">
          <property name="value" type="data">cost</property>
          <property name="locale" type="string">en_CA</property>
        </object>
      </object>
    </widget>
    <widget class="SwatMessageDisplay" id="note" />
    <widget class="SwatActions" id="index_actions">
      <widget class="SwatActionItem" id="havest_date">
        <property name="title">set harvest date…</property>
        <widget class="SwatFormField">
          <property name="title">to month</property>
          <widget class="SwatDateEntry">
            <property name="display_parts" type="constant">MONTH</property>
          </widget>
        </widget>
      </widget>
      <widget class="SwatActionItem" id="makes_jam">
        <property name="title">set jammable…</property>
        <widget class="SwatFormField">
          <property name="title">to</property>
          <widget class="SwatYesNoFlydown">
          </widget>
        </widget>
      </widget>
    </widget>

  </widget>
</swatml>

PHP for this demo:


<?php

/* vim: set noexpandtab tabstop=4 shiftwidth=4 foldmethod=marker: */

require_once 'Demo.php';

/**
 * A demo using a table view
 *
 * @package   SwatDemo
 * @copyright 2005-2007 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 */
class TableViewDemo extends Demo
{
  
// {{{ public function buildDemoUI();

  
public function buildDemoUI(SwatUI $ui)
  {
    
$message = new SwatMessage(
      
'These actions are for demonstration purposes only.');

    
$message->secondary_content =
      
'The actions do not do anything as this page is not connected '.
      
'to a database.';

    
$ui->getWidget('note')->add($messageSwatMessageDisplay::DISMISS_OFF);

    
$data = array(
      array(
'images/apple.png'2828'Apple''red'falsetrue,
        new 
SwatDate('2005-09-01'), 0.5),
      array(
'images/orange.png'2828'Orange''orange'falsefalse,
        new 
SwatDate('2005-04-20'), 0.75),
      array(
'images/strawberry.png'2828'Strawberry''red'truefalse,
        new 
SwatDate('2005-07-05'), 0.6)
    );

    
$table_view $ui->getWidget('table_view');
    
$table_store = new SwatTableStore();

    foreach (
$data as $datum) {
      
$fruit = new FruitObject();
      
$fruit->image $datum[0];
      
$fruit->image_width $datum[1];
      
$fruit->image_height $datum[2];
      
$fruit->title $datum[3];
      
$fruit->color $datum[4];
      
$fruit->makes_jam $datum[5];
      
$fruit->makes_pie $datum[6];
      
$fruit->harvest_date $datum[7];
      
$fruit->cost $datum[8];

      
$table_store->addRow($fruit);
    }

    
$table_view->model $table_store;
  }

  
// }}}
}

/**
 * A demo using a table view
 *
 * @package   SwatDemo
 * @copyright 2005-2006 silverorange
 * @license   http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
 */
class FruitObject
{
  
// {{{ public properties

  
public $image '';
  public 
$image_width 0;
  public 
$image_height 0;
  public 
$title '';
  public 
$color '';
  public 
$makes_jam false;
  public 
$makes_pie false;
  public 
$harvest_date null;
  public 
$cost 0;

  
// }}}
}

?>