Brief analysis of YII2 GridView Implementation Bulk Removal Tutorial GridView Property GridView Set Number of rows GridView Item height

Source: Internet
Author: User
In the circle of friends have children's shoes to me to discuss the problem of the GridView, a friend said you use the GridView to remove my table header link? I think for a long time, with the GridView is really not easy to achieve. Friends with different opinions welcome the message. 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 Activedataprovider ([' query ' = = $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

<?= html::a (' bulk delete ', "javascript:void (0);", [' class ' = ' 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 the $ ("#grid"), with the options ID set by our first step in the same 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 (' $ (". GridView"). On ( "Click", Function () {var keys = $ ("#grid"). Yiigridview ("Getselectedrows"); Console.log (keys);});

The site recommended reading:

Analysis on the common operation of the GridView in Yii2

Yii2 the bottom of the page loading CSS and JS tips

Brief analysis of Yii2 GridView date formatting and implementation date searchable tutorials

Brief analysis of YII2 GridView implementation drop-down search tutorial

The above is a small series to introduce you to the YII2 GridView implementation of bulk deletion tutorial, I hope to help you!

The above on the introduction of the YII2 GridView implementation of the bulk deletion tutorial, including the GridView aspect of the content, I hope that the PHP tutorial interested in a friend helpful.

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