Using YII2 GridView to implement bulk delete cases [GO]

Source: Internet
Author: User

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]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.