gridcolumns Grid View columns to provide column total in the footer, calculate running totals, and calculate values from other columns

  1. Requirements
  2. Documentation
  3. Installation
  4. Usage

A collection of three columns for use with GCridView.

  • TotalColumn - puts the total value in the footer cell
  • RunningTotalColumn - the cell values are running totals (as in a bank account balance)
  • CalcColumn - cell values are calculated from other grid columns. The footer cell value can be the total of column cell values or calculated from other columns (the referenced columns must have the footerCell value)

Use of these columns save going to the model (and perhaps database) for calculations, and can be used with CArrayDataProvider (i.e. where there may not even be a data model).

Requirements

Developed using Yii 1.1.8 but should work with all releases having zii.

Documentation

Properties

All of these columns change the use of the "value" property and add the "output" property.

value string A PHP expression that will be evaluated and whose result will be used as the value (not the rendered output) of the cell; the expression can contain the variables $row - the row number (zero-based), $data - the data model for the row; and $this - the column object. (also see CalcColumn) output string A PHP expression that will be evaluated and whose result will be used to render the footer cell. The expression can contain the variables $value - the footer cell value and $this - the column.

init mixed Either, float: the initial value of the total, or string: A PHP expression that will be evaluated when the grid initialises and whose result becomes the initial value of the total. The expression can contain the variable $this - the column object.

TotalColumn

footer mixed boolean:TRUE means use the output expression to render the value; string: A PHP expression that will be evaluated and whose result will be used to render the footer cell. The expression can contain the variables $value - the footer cell value and $this - the column; any other value means render the footer value as a number.

CalcColumn

value string In addition to the usual variables the expression can reference other grid columns by $cn, where n is the zero-based column number, example: $c0+$c1+$c2 sums the first three columns in the grid. A CalcColumn can be used in the calculation of another CalcColumn; self and circular references are not allowed.

footer mixed boolean:TRUE the footer cell value is the column total; string: a PHP expression that will be evaluated and whose result is the value of the footer cell; the expression can contain the variables $total - the column total, references to other grid columns by $cn (see above; referenced columns must have the "footerCellValue" property), and $this - the column object.

footerOutput mixed If empty the footer cell is not rendered; this property determines whether the column has a footer (see CGridColumn::hasFooter); boolean:TRUE means use the output expression to render the value; string: A PHP expression that will be evaluated and whose result will be used to render the footer cell. The expression can contain the variables $value - the footer cell value and $this - the column; any other value means render the footer value as a number.

Installation

Extract the files in the archive and place in an application directory of your choice.

Usage

Use just like any other grid view column, i.e. in CGridView::columns set the class as the path alias to the column class and declare the properties; e.g.

$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
  'columns'=>array(
     ...
     array(
      'class'=>'path.to.TotalColumn',
      'name'=>'value',
      'output'=>'Yii::app()->getNumberFormatter->formatCurrency($value,'.$currency.')',
      'type'=>'raw',
      'footer'=>true
     ),
     ...
  )
));
17 0
22 followers
1 422 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: Yeti
Created on: Aug 28, 2011
Last updated: 6 years ago

Downloads

show all

Related Extensions