Cgridviews In Tabs

Hello!

Tabs not switch, when i use it with dao-made grids.

Example:

I have class ‘Routes’ made via AR with several attributes,

controller ‘Admin’ and view ‘admin’, made via CRUD. Last one show table with attributes via cgridview.

I make new controller ‘Tabs’ similar on ‘Admin’ and view ‘tabs’.

Several show same ‘admin’ table, some show other views via ‘renderPartial’.

And it works! Pics in attached files.




Controllers


public function actionAdmin()

	{

		$model=new Route('search');

		$model->unsetAttributes(); 

		if(isset($_GET['Route']))

			$model->attributes=$_GET['Route'];


		$this->render('admin',array(

			'model'=>$model,

		));

	}

public function actionTabs($id){


        $modelAdm=new Route('search');

        $modelAdm->unsetAttributes();  


        if(isset($_GET['Route']))

            $modelAdm->attributes=$_GET['Route'];


        $modelCr=new Route;

        $modelUpd=$this->loadModel($id);


        $this->render('tabs', array(

            'modelAdm'=>$modelAdm,

            'modelCr'=>$modelCr,

            'modelUpd'=>$modelUpd,

        ));

    }


View Admin


<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'route-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'num_route',

		'departure_point',

		'destination_point',

		'code_transporter',

		'price',

		'created',

		array(

			'class'=>'CButtonColumn',

		),

	),

));

?>


View tabs


$this->widget('CTabView', array(

    'tabs'=>array(

        'tab1'=>array(

            'title'=>'admin',

            'view'=>'admin',

            'data'=>array('model'=>$modelAdm),

        ),

        'tab2'=>array(

            'title'=>'update',

            'view'=>'update',

            'data'=>array('model'=>$modelUpd),

        ),

        'tab3'=>array(

            'title'=>'create',

            'view'=>'create',

            'data'=>array('model'=>$modelCr),

        ),

        'tab4'=>array(

            'title'=>'admin2',

            'view'=>'admin',

            'data'=>array('model'=>$modelAdm),

        ),

    ),

));



Next i try to do the same with dao-made table(i use several not related tables) and it’s not work




Controller

public function actionTabs(){

        $model = new Trip();

        // here i call the same data with different attributes values

        $routeDM = $model->fillTabs(1);

        $routeMD = $model->fillTabs(2);

        $dmProvider = new CArrayDataProvider($routeDM,

            array(

                'sort'=>array(

                    'defaultOrder'=>'time_start ASC'

                ),

                'pagination'=>array(

                    'pageSize'=>1000,

                ),

                'keyField' => 'num_trip'

            )

        );

        $mdProvider = new CArrayDataProvider($routeMD,

            array(

                'sort'=>array(

                    'defaultOrder'=>'time_start ASC'

                ),

                'pagination'=>array(

                    'pageSize'=>1000,

                ),

                'keyField' => 'num_trip'

            )

        );

        $this->render('tabs',array(

            'dmProvider'=>$dmProvider,

            'mdProvider'=>$mdProvider,

        ));

    }


View tabs

$this->widget('CTabView', array(

    'tabs'=>array(

        'tab1'=>array(

            'title'=>'DM',

            'view'=>'tabContent',

            'data'=>array('itemsProvider'=>$dmProvider),

        ),

        'tab2'=>array(

            'title'=>'MD',

            'view'=>'tabContent2',

            'data'=>array('itemsProvider'=>$mdProvider),

        ),

    ),

));


View tabContent

$this->widget('zii.widgets.grid.CGridView', array(

    'id' => 'itemGrid',

    'ajaxVar'=> true,

    'ajaxUpdate'=> true,

    'cssFile'=>Yii::app()->baseUrl . '/css/bootstrap.css',

    'summaryText'=>'',

    'itemsCssClass'=>'table table-bordered table-striped table-hover',

    'dataProvider' => $itemsProvider,

    'columns' => array(

        array(

            'htmlOptions'=>array(

                'style'=>'text-align:center;'),

            'name' => 'Departure',

            'value' => '$data["departure_point"]'

        ),

        array(

            'htmlOptions'=>array(

                'style'=>'text-align:center;'),

            'name' => 'Destination',

            'value' => '$data["destination_point"]'

        ),

        array(

            'htmlOptions'=>array(

                'style'=>'text-align:center;'),

            'name' => 'Start time',

            'value' => '$data["time_start"]'

        ),

        array(

            'htmlOptions'=>array(

                'style'=>'text-align:center;'),

            'name' => 'Arrival',

            'value' => '$data["time_finish"]'

        ),

        array(

            'htmlOptions'=>array(

                'style'=>'text-align:center;'),

            'name' => 'Price',

            'value' => '$data["price"]'

        ),

        array(

            'htmlOptions'=>array(

                'style'=>'text-align:center;'),

            'name' => 'Places',

            'value' => '$data["places_left"]'

        ),

    ),

));



When i click tab it change url - looks like it send ajax request, but content never change.

What should i do to make it work the same as AC one?

Other idea - to make it with ajaxSubmitButton, wich just replace one grid with another.

Major thing here - show grid with different attributes.

Any ideas, how to solve it?

Thanks in advance!

I’ve found the problem - it was in tabContent view. In start topic i didn’t mention self-made ButtonColumn, but the problem was right there:




array(

            'htmlOptions'=>array(

                'style'=>'width:10px'),

            'class'=>'CButtonColumn',

            'template'=>'{buy}',

            'header'=>'Buy',

            'buttons'=>array(

                'buy' => array(

                    'label'=>'Buy', 

                    'url'=>'$data["num_trip"]',

                    'click'=>'', 

                    'visible'=>'true'                )

            )



When you remove empty ‘click’ option - everything works fine!

Hope it will be useful for someone.