<a href="<?= Url::to(['product-seeds/basket']) ?>">basket</a>
public function actionBasket()
{
VarDumper::dump($_POST,11,1);die;
}
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout' => "{summary}\n{pager}\n{items}\n{pager}",
'columns' => [
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function ($model, $key, $index, $column) {
$model->id; <-- тут не знаю что ставить?
}
], [
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function(){
return [
'onchange' => '
var keys = $("#grid").yiiGridView("getSelectedRows");
$(this).parent().parent().toggleClass("danger")
'
];
}
$("#delete-select").on("click", function(e){
e.preventDefault()
var keys = $("#grid").yiiGridView("getSelectedRows");
$.ajax({
url: "'. \yii\helpers\Url::toRoute('delete') .'",
type: "POST",
data: {id: keys},
success: function(){
alert("yes")
}
})
});
<?php Pjax::begin(); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout' => "{summary}\n{pager}\n{items}\n{pager}",
'columns' => [
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function () {
return [
'onchange' => 'var keys = $("#grid").yiiGridView("getSelectedRows");
$(this).parent().parent().toggleClass("danger")'
];
},
[
'label' => 'Изображения',
'attribute' => 'img_id',
'format' => 'raw',
'options' => ['width' => '100'],
'value' => function ($data) {
return !ProductSeeds::getImageTitle($data->img_id) ? Html::img('/web/uploads/system/no-image.png', ['width' => '50', 'height' => '50', 'class' => 'img-thumbnail']) : Html::img('/web/uploads/products/' . ProductSeeds::getImageTitle($data->img_id), ['width' => '50', 'height' => '50', 'class' => 'img-thumbnail']);
},
'filter' => '',
],
[
'attribute' => 'status',
'format' => 'raw',
'options' => ['width' => '80'],
'value' => function ($data) {
return !$data->status ? '<span class="glyphicon glyphicon-remove text-danger glyphicon-remove-big-size"></span>' : '<span class="glyphicon glyphicon-ok text-success glyphicon-remove-big-size"></span>';
},
'filter' => ProductSeeds::$statuses,
],
[
'attribute' => 'availability',
'format' => 'raw',
'options' => ['width' => '80'],
'value' => function ($data) {
return !$data->availability ? '<span class="glyphicon glyphicon-remove text-danger glyphicon-remove-big-size"></span>' : '<span class="glyphicon glyphicon-ok text-success glyphicon-remove-big-size"></span>';
},
'filter' => ProductSeeds::$availabilities,
],
[
'attribute' => 'hit',
'format' => 'raw',
'options' => ['width' => '80'],
'value' => function ($data) {
return !$data->hit ? '<span class="glyphicon glyphicon-remove text-danger glyphicon-remove-big-size"></span>' : '<span class="glyphicon glyphicon-ok text-success glyphicon-remove-big-size"></span>';
},
'filter' => ProductSeeds::$hits,
],
[
'attribute' => 'new',
'format' => 'raw',
'options' => ['width' => '80'],
'value' => function ($data) {
return !$data->new ? '<span class="glyphicon glyphicon-remove text-danger glyphicon-remove-big-size"></span>' : '<span class="glyphicon glyphicon-ok text-success glyphicon-remove-big-size"></span>';
},
'filter' => ProductSeeds::$novelty,
],
[
'attribute' => 'sale',
'format' => 'raw',
'options' => ['width' => '80'],
'value' => function ($data) {
return !$data->sale ? '<span class="glyphicon glyphicon-remove text-danger glyphicon-remove-big-size"></span>' : '<span class="glyphicon glyphicon-ok text-success glyphicon-remove-big-size"></span>';
},
'filter' => ProductSeeds::$sales,
],
[
'attribute' => 'top_sales',
'format' => 'raw',
'options' => ['width' => '80'],
'value' => function ($data) {
return !$data->top_sales ? '<span class="glyphicon glyphicon-remove text-danger glyphicon-remove-big-size"></span>' : '<span class="glyphicon glyphicon-ok text-success glyphicon-remove-big-size"></span>';
},
'filter' => ProductSeeds::$topSales,
],
[
'attribute' => 'top_ten',
'format' => 'raw',
'options' => ['width' => '80'],
'value' => function ($data) {
return !$data->top_ten ? '<span class="glyphicon glyphicon-remove text-danger glyphicon-remove-big-size"></span>' : '<span class="glyphicon glyphicon-ok text-success glyphicon-remove-big-size"></span>';
},
'filter' => ProductSeeds::$topTen,
],
[
'attribute' => 'category_id',
'options' => ['width' => '150'],
'value' => function ($data) {
return $data->category->title;
},
'filter' => ArrayHelper::map(CategorySeeds::find()->all(), 'id', 'title'),
],
[
'attribute' => 'title',
'format' => 'raw',
//'options' => ['width' => '180'],
'filter' => '',
],
[
'attribute' => 'price',
'headerOptions' => ['width' => '100'],
],
[
'attribute' => 'old_price',
'headerOptions' => ['width' => '100'],
],
[
'class' => 'yii\grid\ActionColumn',
'header' => 'Действие',
'headerOptions' => ['width' => '65'],
'template' => '{view} {update} {delete}{link}',
],
],
]); ?>
<?php Pjax::end(); ?>
</div>
<?php
$script = <<< JS
$("#basket").on("click", function(e){
e.preventDefault()
var keys = $("#grid").yiiGridView("getSelectedRows");
$.ajax({
url: "'. \yii\helpers\Url::toRoute('basket') .'",
type: "POST",
data: {id: keys},
success: function(){
alert("yes")
}
})
});
JS;
$this->registerJs($script, yii\web\View::POS_READY);
?>
'columns' => [
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function () {
return [
'onchange' => 'var keys = $("#grid").yiiGridView("getSelectedRows");
$(this).parent().parent().toggleClass("danger")'
];
},
'columns' => [
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function ($model, $key, $index, $column) {
$model->id; <-- тут не знаю что ставить?
}
],
var keys = $("#grid").yiiGridView("getSelectedRows"); на var keys = $("#w0").yiiGridView("getSelectedRows");
.<?= Html::submitButton('Удалить выбранные', ['class' => 'btn btn-success', 'id' => 'delete-select']) ?>
TypeError: data is undefinedyii.gridView.js:207:17
getSelectedRows site.local/backend/web/assets/a18f8ac7/yii.gridVie...
yiiGridView site.local/backend/web/assets/a18f8ac7/yii.gridVie...
onchange site.local/backend/web/index.php?r=category:2
jQuery 6
setSelectionColumn site.local/backend/web/assets/a18f8ac7/yii.gridVie...
jQuery 2
$("#delete-select").on("click", function(e){
e.preventDefault()
var keys = $("#grid").yiiGridView("getSelectedRows");
$.ajax({
url: "'. \yii\helpers\Url::toRoute('delete') .'",
type: "POST",
data: {id: keys},
success: function(){
alert("yes")
}
})
});
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function () {
return [
'onchange' => 'var keys = $("#grid").yiiGridView("getSelectedRows");
$(this).parent().parent().toggleClass("danger")'
];
},
],
getSelectedRows: function () {
var $grid = $(this);
var data = gridData[$grid.attr('id')];
var keys = [];
if (data.selectionColumn) {
$grid.find("input[name='" + data.selectionColumn + "']:checked").each(function () {
keys.push($(this).parent().closest('tr').data('key'));
});
}
return keys;
},
<?=
GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'summary' => false,
'columns' => [
// ['class' => 'yii\grid\SerialColumn'],
[
'class' => 'yii\grid\CheckboxColumn',
'checkboxOptions' => function () {
return [
'onchange' => 'var keys = $("#grid").yiiGridView("getSelectedRows");
$(this).parent().parent().toggleClass("danger")'
];
},
],
//'id',
'slug',
'name',
'title',
'meta_descriptions:ntext',
//'status',
//'user_id',
//'tree_id',
//'created_at',
//'updated_at',
['class' => 'yii\grid\ActionColumn'],
],
]);
?>
$("#delete-select").on("click", function(e){
e.preventDefault()
var keys = $("#grid").yiiGridView("getSelectedRows");
$.ajax({
url: "'. \yii\helpers\Url::toRoute('delete') .'",
type: "POST",
data: {id: keys},
success: function(){
alert("yes")
}
})
});