Example #1
0
 /**
  * Generates datagrid headrer.
  * @return Html
  */
 protected function generateHeaderRow()
 {
     $row = $this->getWrapper('row.header container');
     // checker
     if ($this->dataGrid->hasOperations()) {
         $cell = $this->getWrapper('row.header cell container');
         $cell->addClass('checker');
         if ($this->dataGrid->hasFilters()) {
             $cell->rowspan(2);
         }
         $row->add($cell);
     }
     // headers
     foreach ($this->dataGrid->getColumns() as $column) {
         $value = $text = $column->caption;
         if ($column->isOrderable()) {
             $i = 1;
             parse_str($this->dataGrid->order, $list);
             foreach ($list as $field => $dir) {
                 $list[$field] = array($dir, $i++);
             }
             if (isset($list[$column->getName()])) {
                 $a = $list[$column->getName()][0] === 'a';
                 $d = $list[$column->getName()][0] === 'd';
             } else {
                 $a = $d = FALSE;
             }
             if (count($list) > 1 && isset($list[$column->getName()])) {
                 $text .= Html::el('span')->setHtml($list[$column->getName()][1]);
             }
             $up = clone $down = Html::el('a')->addClass(Columns\Column::$ajaxClass);
             $up->addClass($a ? 'active' : '')->href($column->getOrderLink('a'))->add(Html::el('span')->class('up'));
             $down->addClass($d ? 'active' : '')->href($column->getOrderLink('d'))->add(Html::el('span')->class('down'));
             $positioner = Html::el('span')->class('positioner')->add($up)->add($down);
             $active = $a || $d;
             $value = (string) Html::el('a')->href($column->getOrderLink())->addClass(Columns\Column::$ajaxClass)->setHtml($text) . $positioner;
         } else {
             $value = (string) Html::el('p')->setText($value);
         }
         $cell = $this->getWrapper('row.header cell container')->setHtml($value);
         $cell->attrs = $column->getHeaderPrototype()->attrs;
         $cell->addClass(isset($active) && $active == TRUE ? $this->getValue('row.header cell .active') : NULL);
         if ($column instanceof Columns\ActionColumn) {
             $cell->addClass('actions');
         }
         $row->add($cell);
     }
     return $row;
 }