How to pass previous and back element's id in yii grideview?

78 Views Asked by At

I am trying to create a link in yii1.1's grideview with it's id and its previous and back elements id.

array(
    'class' => 'bootstrap.widgets.TbButtonColumn',
    'template' => '{manage}',
    'buttons' => array(
        'manage' => array(
            'label' => 'Manage',
            'icon' => 'th',                            
            'url' => Yii::app()->createUrl(
                "/member/data/manage",
                array("id" => $data->id, "prev" => ???, "post" => ???)
            ),
        ),
    ),
),

Here is my desired output. enter image description here

1

There are 1 best solutions below

0
Khalil Majdalawi On

try bellow code, not pretty solution but should work

array(
    'class' => 'bootstrap.widgets.TbButtonColumn',
    'template' => '{manage}',
    'buttons' => array(
        'manage' => array(
            'label' => 'Manage',
            'icon' => 'th',                            
            'url' => function ($data, $row, $widget) {
                    $pagination = $widget->grid->dataProvider->getPagination();
                    $widget->grid->dataProvider->setPagination(false);
                    $provider_data = $widget->grid->dataProvider->getData();
                    $widget->grid->dataProvider->setPagination($pagination);
                    return Yii::app()->createUrl(
                        "/member/data/manage",
                        array(
                            "id" => $data->id,
                            "prev" => isset($provider_data[$row - 1]) ? $provider_data[$row - 1]->id : '',
                            "post" => isset($provider_data[$row + 1]) ? $provider_data[$row + 1]->id : ''
                        )
                    );
                },
        ),
    ),
),