0
echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            [
                'class' => CheckboxColumn::class
            ],
            [
                'attribute' => 'id',
                'value' => function (Advert $model) {
                    return Html::a($model->id, $model->source);
            },
                'format' => 'raw'
            ],
            [
                'attribute' => 'photos_number',
                'label' => 'Картинка',
                'value' => function (Advert $model) {
                    if (!empty($model->photos)) {
                        return Image::img($model->photos[0], ['hp' => 150, 'wl' => 150, 'far' => 'C', 'bg' => 'ffffff']);
                    }
                    return null;
                },
                'format' => 'raw'
            ],
 ['class' => 'yii\grid\ActionColumn',],
        ],

Подскажите, может кто сталкивался. Выбранные в гриде Checkbox нужно открыть в новой вкладке по одному клику, к примеру по кнопке.

1 ответ 1

1

Можно назначить чекбоксу класс и передать в его data ссылку, на которую нужно перейти. По нажатию кнопки открывать ссылки в отдельных окнах.

[
    'class' => \yii\grid\CheckboxColumn::class,
    'checkboxOptions' => function ($model, $key, $index, $column) {
        return ['class' => 'checkboxClass', 'data-target' => $model->source];
    }
]

Если используешь jQuery:

$('#yourButton').click(function(e) {
    $(input.checkboxClass:checked).each(function(index, item){
        window.open($(item).data('target'));
    });
});

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.