<?php require_once dirname(__FILE__) . '/../../anewt.lib.php'; anewt_include('page'); anewt_include('renderer/grid'); $grid = new AnewtGridRenderer(); $column = new AnewtGridColumn('col-2', 'Second column', 2); $grid->add_column($column); $column = new AnewtGridColumn('somecol', 'First column', 1); $cell_renderer = new AnewtGridCellRenderer('col-1a', 'Column 1a'); $cell_renderer->set('title', 'Column 1a'); $column->add_cell_renderer($cell_renderer); $cell_renderer = new AnewtGridCellRenderer('col-1b', 'Column 1b'); $cell_renderer->set('title', 'Column 1b'); $column->add_cell_renderer($cell_renderer); $grid->add_column($column); $rows = array(array('col-1a' => 'r1c1a', 'col-1b' => 'r1c1b', 'col-2' => 'r1c2'), array('col-1a' => 'r2c1a', 'col-1b' => 'r2c1b', 'col-2' => 'r2c2')); $grid->set_rows($rows); $grid->add_row(array('col-1a' => 'r3c1a', 'col-2' => 'r3c2')); $p = new AnewtPage(); $p->set('title', 'Anewt Grid Renderer'); $p->append($grid); $p->flush();
/** * Add a counter column to the grid. This is a convenience function that * adds a column with id <code>count</code> and a AnewtCountGridCellRenderer * with id <code>count</code> as the first column in the grid. * * \param $header_text * The header text to use (optional, defaults to empty string; leave null * to use default) * * \param $initial_value * The initial value (optional, defaults to standard numbering; leave null * to use default) */ function add_count_column($header_text = null, $initial_value = null) { if (is_null($header_text)) { $header_text = ''; } assert('is_string($header_text)'); /* Force the count column to be the leftmost column by giving it a very * negative 'order' property. */ $order = -100; $column = new AnewtGridColumn('count', $header_text, $order); $column->add_cell_renderer(new AnewtGridCellRendererCount('count', $initial_value)); $this->add_column($column); }