Search code examples
phpphpgrid

Add static column in phpgrid manually


Using phpgrid.com to create a datagrid. Now i want to add a column named XYZ and with contents as ABC for all rows. Is it possible? The content is static for all rows and wont change at all. The column is not fetched from mysql table.


Solution

  • You need to use virtual column add_column

    http://phpgrid.com/example/virtual-column-aka-calculated-column/

    $col_formatter = <<<COLFORMATTER
    function(cellvalue, options, rowObject){    
        return "ABC";
    }
    COLFORMATTER;
    
    $dg -> add_column(
            'XYZ', 
            array('name'=>'XYZ', 
                'index'=>'XYZ', 
                'width'=>'360', 
                'align'=>'left', 
                'sortable'=>false,
                'formatter'=>$col_formatter),
            'XYZ');