/**
  * Renders data grid paginator.
  * @return string
  */
 public function renderPaginator()
 {
     $paginator = $this->dataGrid->paginator;
     if ($paginator->pageCount <= 1) {
         return '';
     }
     $container = $this->getWrapper('paginator container');
     $translator = $this->dataGrid->getTranslator();
     $a = Html::el('a');
     $a->addClass(DataGridAction::$ajaxClass);
     // to-first button
     $first = $this->getWrapper('paginator button first');
     $title = $this->dataGrid->translate('First');
     $link = clone $a->href($this->dataGrid->link('page', 1));
     if ($first instanceof Html) {
         if ($paginator->isFirst()) {
             $first->addClass('inactive');
         } else {
             $first = $link->add($first);
         }
         $first->title($title);
     } else {
         $first = $link->setText($title);
     }
     $container->add($first);
     // previous button
     $prev = $this->getWrapper('paginator button prev');
     $title = $this->dataGrid->translate('Previous');
     $link = clone $a->href($this->dataGrid->link('page', $paginator->page - 1));
     if ($prev instanceof Html) {
         if ($paginator->isFirst()) {
             $prev->addClass('inactive');
         } else {
             $prev = $link->add($prev);
         }
         $prev->title($title);
     } else {
         $prev = $link->setText($title);
     }
     $container->add($prev);
     // page input
     $controls = $this->getWrapper('paginator controls container');
     $form = $this->dataGrid->getForm(TRUE);
     $format = $this->dataGrid->translate($this->paginatorFormat);
     $html = str_replace(array('%label%', '%input%', '%count%'), array($form['page']->label, $form['page']->control, $paginator->pageCount), $format);
     $controls->add(Html::el()->setHtml($html));
     $container->add($controls);
     // next button
     $next = $this->getWrapper('paginator button next');
     $title = $this->dataGrid->translate('Next');
     $link = clone $a->href($this->dataGrid->link('page', $paginator->page + 1));
     if ($next instanceof Html) {
         if ($paginator->isLast()) {
             $next->addClass('inactive');
         } else {
             $next = $link->add($next);
         }
         $next->title($title);
     } else {
         $next = $link->setText($title);
     }
     $container->add($next);
     // to-last button
     $last = $this->getWrapper('paginator button last');
     $title = $this->dataGrid->translate('Last');
     $link = clone $a->href($this->dataGrid->link('page', $paginator->pageCount));
     if ($last instanceof Html) {
         if ($paginator->isLast()) {
             $last->addClass('inactive');
         } else {
             $last = $link->add($last);
         }
         $last->title($title);
     } else {
         $last = $link->setText($title);
     }
     $container->add($last);
     // page change submit
     $control = $form['pageSubmit']->control;
     $control->title = $control->value;
     $container->add($control);
     unset($first, $prev, $next, $last, $button, $paginator, $link, $a, $form);
     return $container->render();
 }