Display Subtotal per item using Gridview


Im new to Yii2.0 and I have a problem figuring out how to display a subtotal row in Gridview. I hope somebody can help me. I know there is this renderRowTable but I do not know how to use it. can somebody help me by providing some sample code?

Attached is the end result of the screen that i want to do.

i give just hint…

use 2amigos/yii2-gridview and in GroupGridView class that just edit renderExtraRow function

protected function renderExtraRow($model, $key, $index, $totals)


        if ($this->extraRowValue instanceof Closure) {

            $content = call_user_func($this->extraRowValue, $model, $index, $totals);

        } else {

            $values = [];

            foreach ($this->extraRowColumns as $name) {

                $values[] = ArrayHelper::getValue($model, $name);


            $content = '<strong>' . implode(' :: ', $values) . '</strong>';


        $colspan = count($this->columns);

       /*  add following */

	$cell = Html::tag('td', 'Sub Total', ['class' => $this->extraRowClass, 'colspan' => $colspan]);


        $cell = Html::tag('td', $content, ['class' => $this->extraRowClass, 'colspan' => $colspan]);

        return Html::tag('tr', $cell);


than for subtotal use this in grid view:

 'extraRowTotalsValue' => function($data, $row, &$totals) { 

    /* this is example function make yours subtotal attribute...*/

          if(!isset($totals['sum_credit'])) $totals['sum_credit'] = 0;

          $totals['sum_credit'] += $data['relSubject']['credits'];


after configure Grid view extra row setting as per your requirements…

Also you can subclass GridView widget and override renderFooter method.


thanks for the reply! Actually I prefer not to use extention unless there is really no way out. :)

can i know how to use the renderFooter method? do you have any sample code of that?