Question

I am trying to render the Cgridview with dynamic columns using the input dates (columns dynamically starts from from_dt to to_date) ,

Now i want to give Chtml::link for dynamic columns but i am getting error undefined index : "01" (dynamic columns ).

$columns =array(array('name'=>'Agents', 'header'=>'Agents', 

'htmlOptions'=>array('style'=>'width: 300px')), 
array('name'=>'category',  'cssClassExpression' => '$data["category"]== "Total" ? "Total" :($data["postcode"] != "" ? "Sub" :$data["category"] )' ,'header'=>'Category','htmlOptions'=>array('style'=>'width: 300px;')),    
array('name'=>'postcode', 'header'=>'PostCode','htmlOptions'=>array('style'=>'width: 350px')),
array('name'=>'TotalPeriod', 'header'=>'TotalPeriod'),
array('name'=>'percent', 'header'=>'%','htmlOptions'=>array('style'=>'width: 350px')),
); 
//Dynamic Column Rendering code
    for($i=0;$i < $numberDays ; $i++)
    {

        if ($i != 0)
            $start =  date('d-m-Y', strtotime("+1 day", strtotime($start)));

        $timestamp = strtotime($start);
        $columns[] = array('name'=>date("d", $timestamp), 'header'=>date("d", $timestamp), 'value' =>'CHtml::link($data[date("d", '.$timestamp.')],"http://www.google.com",array("target"=>"_blank"))',  'type'  => 'raw',);

    } 

enter image description here

Was it helpful?

Solution

Please check the below working code,

for($i=0;$i < $numberDays ; $i++)
    {

        if ($i != 0)
            $start =  date('Y-m-d', strtotime("+1 day", strtotime($start)));

        $timestamp = strtotime($start);
        $day =  date("d", $timestamp);
        $columns[] = array('name'=>date("d", $timestamp), 'header'=>date("d", $timestamp), 'value' =>'getVal($data,"'.$day.'") > 0 ? CHtml::link(getVal($data,"'.$day.'")," ",array("class"=>"drillDay","id"=>"'.$start.'")) : getVal($data,"'.$day.'")', 'type'  => 'raw');
        //$columns[] =  date("d", $timestamp);
        //$datatemp[$start] = $start;
    } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top