Search code examples
javascriptphpjqueryjqgridphpgrid

Changing the position of virtual column phpgrid


In phpgrid I have added a virtual column (column not existing in db) using the add_column method. But the problem is I cannot make it appear it in the first position(i.e first column of the table). Documentation for the add_column method says that it will be appended at the end of the other columns add_method for phpgrid. Is it possible to add it in the first column/position? I tried various jquery hacks but none seems to be useful.

Below is the code for add_column

PHP code

$dg->add_column("custom", array('name'          => 'custom',
                                'index'         => 'custom',
                                'width'         => '100',
                                'formatter'     => '###customAction###',
                                'formatoptions' => array('keys' => true, 'editbutton' => true, 'delbutton' => true)), 'Custom Action');

JAVASCRIPT code

function customAction(cellValue, options, rowdata) {
        output = '<span class="custom-action"><i class="glyphicon glyphicon-plus custom" data-transaction-id="' + options.rowId + '"></i></span>';
        return output;
    }

Solution

  • The last parameter indicates the column position.

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

    This should put the virtual column to the index 0, the first column.