yii\grid\GridView::renderTableBody PHP Method

renderTableBody() public method

Renders the table body.
public renderTableBody ( ) : string
return string the rendering result.
    public function renderTableBody()
    {
        $models = array_values($this->dataProvider->getModels());
        $keys = $this->dataProvider->getKeys();
        $rows = [];
        foreach ($models as $index => $model) {
            $key = $keys[$index];
            if ($this->beforeRow !== null) {
                $row = call_user_func($this->beforeRow, $model, $key, $index, $this);
                if (!empty($row)) {
                    $rows[] = $row;
                }
            }
            $rows[] = $this->renderTableRow($model, $key, $index);
            if ($this->afterRow !== null) {
                $row = call_user_func($this->afterRow, $model, $key, $index, $this);
                if (!empty($row)) {
                    $rows[] = $row;
                }
            }
        }
        if (empty($rows)) {
            $colspan = count($this->columns);
            return "<tbody>\n<tr><td colspan=\"{$colspan}\">" . $this->renderEmpty() . "</td></tr>\n</tbody>";
        } else {
            return "<tbody>\n" . implode("\n", $rows) . "\n</tbody>";
        }
    }

Usage Example

Example #1
0
 /**
  * @inheritdoc
  * @return string the rendering result.
  */
 public function renderTableBody()
 {
     if (!$this->showHeader) {
         return parent::renderTableBody();
     }
     $models = array_values($this->dataProvider->getModels());
     $keys = $this->dataProvider->getKeys();
     $rows = [];
     foreach ($models as $index => $model) {
         $key = $keys[$index];
         if ($this->beforeRow !== null) {
             $row = call_user_func($this->beforeRow, $model, $key, $index, $this);
             if (!empty($row)) {
                 $rows[] = $row;
             }
         }
         $rows[] = $this->renderTableRow($model, $key, $index);
         if ($this->afterRow !== null) {
             $row = call_user_func($this->afterRow, $model, $key, $index, $this);
             if (!empty($row)) {
                 $rows[] = $row;
             }
         }
     }
     if (empty($rows)) {
         $colspan = count($this->columns);
         return "\n<tr><td colspan=\"{$colspan}\">" . $this->renderEmpty() . "</td></tr>\n</tbody>";
     } else {
         return "\n" . implode("\n", $rows) . "\n</tbody>";
     }
 }
All Usage Examples Of yii\grid\GridView::renderTableBody