public function test_render() { $collection = Jam::all('test_city')->load_fields(array(array('id' => 1, 'name' => 'London', 'population' => 10), array('id' => 2, 'name' => 'New York', 'population' => 15))); $name = new Tart_Column(); $name->sort(FALSE); $population = new Tart_Column(); $population->sort(FALSE); $columns = array('name' => $name, 'population' => $population); $table = new Tart_Table($collection, $columns); $table->selected(FALSE); $expected = <<<HTML <table class="table table-striped table-hover"> <thead> <th>Name</th> <th>Population</th> </thead> <tbody> <tr class="test_city-1"> <td>London</td> <td>10</td> </tr> <tr class="test_city-2"> <td>New York</td> <td>15</td> </tr> </tbody> </table> HTML; $this->assertSame($expected, $table->render()); $table->selected(array(1)); $expected = <<<HTML_SELECTED <table class="table table-striped table-hover"> <thead> <th width="10"> <input type="checkbox" name="all" value="1"/> </th> <th>Name</th> <th>Population</th> </thead> <tbody> <tr class="test_city-1"> <td> <input type="checkbox" name="id[]" value="1" checked="1"/> </td> <td>London</td> <td>10</td> </tr> <tr class="test_city-2"> <td> <input type="checkbox" name="id[]" value="2"/> </td> <td>New York</td> <td>15</td> </tr> </tbody> </table> HTML_SELECTED; $this->assertSame($expected, $table->render()); }
public function test_set_filter() { $column = new Tart_Column(); $filter = new Tart_Filter(array()); $table = new Tart_Table(Jam::all('test_city')); $column->item($this->city); $column->set_filter($filter, 'area'); $rendered = (string) $column->name('name')->item($this->city)->render(); $this->assertSelectEquals('span[data-provide="filters"][draggable="true"][data-dropzone=".tart-filter"', 'Bigville', TRUE, $rendered); }
public function render() { if (!$this->item()) { throw new Kohana_Exception('You must assign an item before you render'); } if ($callback = $this->callback()) { $content = call_user_func($callback, $this->item(), $this->name(), $this); } elseif ($field = $this->item()->meta()->field($this->name())) { $content = Tart_Column::render_field($this->item(), $field); } elseif ($association = $this->item()->meta()->association($this->name())) { $content = Tart_Column::render_association($this->item(), $association); } else { $content = (string) $this->item()->{$this->name()}; } if ($content) { if ($this->_filter and $this->_filter_name and $this->_is_link) { $content = $this->_filter->anchor($this->_filter_name, Jam_Form::list_id($this->item()->{$this->name()}), $content, array('href' => Tart::uri($this->item()->{$this->name()}))); } if ($this->_is_link) { $content = HTML::anchor(Tart::uri($this->item()->{$this->name()}), $content); } if ($this->_filter and $this->_filter_name) { $content = $this->_filter->anchor($this->_filter_name, Jam_Form::list_id($this->item()->{$this->name()}), $content); } } return $content; }
/** * Getter / Setter for the width, defaults to 105, and 180 when sortable * @param integer $width * @return integer|$this */ public function width($width = NULL) { if ($width !== NULL) { return parent::width($width); } if ($this->_width === NULL) { $this->_width = $this->sortable() ? 180 : 105; } return $this->_width; }