Today still continue to discuss the problem of the GridView, yesterday a little friend said you use the GridView to get me out of the table header link? I think, I think, this is not easy to achieve with the GridView, at least I did not want to come out, will be a message below. However, this GridView has a yarn related ah, obviously is to set activedataprovider, you want me how to use the GridView implementation.
This question is also very simple, let's take a look at the concrete implementation
New Activedataprovider ([ $dataProvider->setsort (false);
It's not a matter of minutes.
OK, let's talk about the topic: How to use YII2 GridView to implement bulk deletion?
I first say a few steps ah, so as to avoid direct code some of the small partners deleted a sentence to a last failure!
1, the GridView SET options when you add an ID here we name grid
"Options" = [ //...] Other settings "Grid"],
2, Columns add the option check box, bulk deletion must not be less than the check box operation, here our Name value is set to ID, convenient for data operation
[ "Yii\grid\checkboxcolumn", "id",],
3, the page we added a batch delete button, note here we added a class gridview, convenient to the back JS implementation click Effect
<?= html::a ("javascript:void (0);", [?>
4, the last step, write JS implementation button operation, open your console to see, we are very easy to get the ID of the selected row, and then here you can operate the data asynchronously.
<?php$this->registerjs (' $ (". GridView"). On ("click", Function () {///note here for $ ("#grid"), with the options that we set for the first step ID consistent var keys = $ ("#grid"). Yiigridview ("Getselectedrows"); Console.log (keys);}); ?>
The complete code is affixed below
Gridview::widget ([// ...... "options" = [ "class" = " Grid-view ", " style "=>" Overflow:auto ", "id" = "grid"], //... "columns" = [//... [ "class" = "Yii\grid\checkboxcolumn", "name" = = "id", "//...]); $this->registerjs ( ' $ (document). On (' Click
Using YII2 GridView to implement bulk delete cases [go]