Using YII2 GridView to implement bulk delete cases, yii2gridview_php tutorials

Source: Internet
Author: User
Tags yii

Use YII2 GridView to implement bulk delete cases, Yii2gridview


Author: White Wolf Source: http://www.manks.top/article/yii2_gridview_deleteall This article copyright belongs to the author, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location gives the original text connection, Otherwise, the right to pursue legal liability is retained.

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

$dataProvider New  $query,$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 ' id ' = ' 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

[    ' class ' = ' Yii\grid\checkboxcolumn ',    ' name ' = ' 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

 
  ' Btn btn-success GridView '])?>

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"), Be consistent with the options ID we set for the first step    var keys = $ ("#grid"). Yiigridview ("Getselectedrows");    Console.log (keys);});' );? >

The complete code is affixed below

GridView::widgets ([        //  ...        ] Options ' = ' + [' class ' = ' Grid-view ', ' style ' = ' overflow:auto ', ' id ' = ' grid '],        //  ... /c7>        ' columns ' = [            //  ... ]             [                ' class ' = ' Yii\grid\checkboxcolumn ',                ' name ' = ' id ',            ],            //  ......        ],]); $this->registerjs ('$ (". GridView"). On ("click", Function () {    var keys = $ ("#grid"). Yiigridview ("Getselectedrows");    Console.log (keys);});

http://www.bkjia.com/PHPjc/1122762.html www.bkjia.com true http://www.bkjia.com/PHPjc/1122762.html techarticle using YII2 GridView to implement the bulk deletion case, Yii2gridview Author: White Wolf Source: http://www.manks.top/article/yii2_gridview_deleteall This article copyright to the author, Welcome reprint, but without ...

  • 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.