add_column()

  • Parameter(s):
    • $col_name: Name of the calculated/virtual column. It cannot have space and must NOT be one of the existing database column names.
    • $property: Column properties. See set_col_property() for available column properties usage.
    • $title: Optional. Title for this virtual column. If omitted, it’s the same as the column name $col_name.
  • Description:
    • Append virtual column, AKA calculated column, to the end of an existing datagrid with this method.
  • Remark:
    • The $col_name cannot contain space and must begin with a letter
    • Use “formatter” column property to hook up Javascript function, e.g. below, $col_formatter is the Javascript to display value in virtual column.
    • The virtual column always adds to the end of the grid in the order of virtual column is created.
    • Text must be surrounded with SINGLE quote.
    • Virtual column is not sortable.
  • Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$col_formatter = <<<COLFORMATTER
function(cellvalue, options, rowObject){
var n1 = parseInt(rowObject[0],10),    // get value from column #1
n2 = parseInt(rowObject[6],10);        // get value from column #7
return n1+n2;    
}
COLFORMATTER
;

$dg -> add_column(
        'total',
        array('name'=>'total',
            'index'=>'total',
            'width'=>'360',
            'align'=>'right',
            'formatter'=>$col_formatter),
        'Total (Virtual)');