3

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

Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
Anil Chaudhari
  • 801
  • 14
  • 30
  • Humm.. I didn't find any answers yet. So I have some alternative options either I have to use `JavaScript` to pass those ids or I have to run custom `SQL` in the desired view.. – Anil Chaudhari Jan 01 '16 at 05:24
  • Are you using ActiveRecord as your database layer? And is there any logical relations between your records? does current object relates to the past in a logical way? same for next record? – Mohamad Eghlima Jan 19 '16 at 19:33

1 Answers1

0

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 : ''
                        )
                    );
                },
        ),
    ),
),