CGridView and ajaxLink in column

Hi everybody,

I’ve taken a look to the forum during hours, but unfortunatly I didn’t found yet an answer.

I’ve an admin page which manage products with a gridview. In this gridview, one of the columns contains an ajaxLink which allow to change the product status (available or not).

In the first page, the links work without any problem, but when am going to another page (refreshed in ajax), the bouton has no ajaxlink linked…

Here is my view code :


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

    'id' => 'product-grid',

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

    'filter' => $model,

    'columns' => array(

        array(

            'name' => 'id',

            'htmlOptions' => array('style' => 'width: 25px; text-align: center;'),

        ),

        array(

            'name' => 'category_id',

            'filter' => CHtml::listData(Category::getAllIndentedCategories(), 'id', 'name'),

            'value' => '$data->category->getAbsolutePath()',

        ),




        //This one bug

        array(

            'name' => 'Produit Arreté',

            'value' => '$data->getStoppedProductButton()',

            'type' => 'raw',

            'filter' => false,

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

        ),




        array(

            'name' => 'image',

            'value' => '$data->getImage(60,60)',

            'type' => 'raw',

            'filter' => false,

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

        ),

        array(

            'name' => 'title',

            'value' => '(!empty($data->productSite2ProductPlateformes))?$data->getTitle(1,1):"Pas de produit lié"',

            'type' => 'raw',

            'headerHtmlOptions' => array('width' => '300px'),

        ),

        array(

            'name' => 'fournisseur_id',

            'filter' => CHtml::listData(Fournisseur::model()->findAll(array('order' => 'fournisseurs_name')), 'fournisseurs_id', 'fournisseurs_name'),

            'value' => '$data->fournisseur->fournisseurs_name',

        ),

        'fournisseur_reference',

        array(

            'name' => 'stock',

            'htmlOptions' => array('style' => 'text-align:right;',),

        ),

        array(

            'class' => 'CButtonColumn',

            'template' => '{view}{update}{destock}{restock}',

            'buttons' => array(

                'destock' => array(

                    'label' => '<span style="color: red">[-]</span>',

                    'type' => 'html',

                    'url' => 'Yii::app()->createUrl("product/updateStock",array("product_id"=>$data->id,"method"=>"destock"))',

                ),

                'restock' => array(

                    'label' => '<span style="color: green">[+]</span>',

                    'url' => 'Yii::app()->createUrl("product/updateStock",array("product_id"=>$data->id,"method"=>"restock"))',

                ),

            ),

        ),

    ),

)); ?>

Here is my model code :


public function getStoppedProductButton($with_span = 1)

    {

        $result = null;

        if (!$this->produit_arrete) {

            $result .= CHtml::ajaxLink(CHtml::image(Yii::app()->request->baseUrl . '/images/buttons/' .

                    'icon_arret_light.png', 'Non arreté', array('height' => '40',)),

                array('/product/setStoppedProduct', 'id' => $this->id),

                array(

                    'update' => '#updateArretDiv_' . $this->id

                ),

                array(

                    'title' => 'Non arreté',

                    'id' => 'updatedArret' . $this->id,

                    'confirm' => 'Mettre le produit arreté ?'

                ));

        } else {

            $result .= CHtml::ajaxLink(CHtml::image(Yii::app()->request->baseUrl . '/images/buttons/' .

                    'icon_arret.png', 'Produit arreté', array('height' => '40',)),

                array('/product/setStoppedProduct', 'id' => $this->id),

                array(

                    'update' => '#updateArretDiv_' . $this->id

                ),

                array(

                    'title' => 'Produit arreté',

                    'id' => 'updatedArret' . $this->id,

                    'confirm' => 'Enlever le produit arreté ?'

                ));

        }


        if ($with_span)

            return '<div id="updateArretDiv_' . $this->id . '">' . $result . '</span>';

        else

            return $result;

    }

In my opinion, because of the ajaxLink is created in the model, no script is created for the others pages (or the search when the product is in other page than the first).

I have more than 7000 products, and I have no idea to resolve my problem…

I could change the model function (to give only an unique id) and create a script on my view which allow to do the same proccess. (I guess…)

Guys, do you have ideas ?

Thanks a lot ! :rolleyes:

can you try to include the ajax code to the rendered page instead of using the built-in yii ajax functionality and see if it works that way.