Formatting Dynamic Columns


I am showing data in CGridView from a dynamic SQL Query using CSqlDataProvider. There are some static and some dynamic column. Now I want to do some special formatting like currency in the dynamic columns. But how do I do that when I don’t know the number/name of the columns till the query is executed.

Also i want to be able to sort the dynamic columns and again I have the same problem that I don’t have all the column names.

Anyone before who worked with dynamic queries and gridview. Could please point me to the right direction or give some ideas how to do it.

In short I am able to successfully show the data in gridview(also dynamic rows) and sort all the static columns. Just need to sort dynamic rows and format dynamic & static columns

This is the code for gridview:

$this->widget('bootstrap.widgets.TbExtendedGridView', array(


    'afterSortableUpdate' => 'js:function(id, position){ console.log("id: "+id+", position:"+position);}',

    'type'=>'striped bordered hover',


    'type'=>'striped bordered',

    'template' => "{items}\n{extendedSummary}",

    'columns'=> $grid_final, 



Still looking for a solution to sort dynamic columns


You can look at this wiki: Sort and filter a custom or composite CGridView column.