Home Backend Development PHP Tutorial Yii2 uses GridView to implement buttons for selecting all data and deleting data in batches

Yii2 uses GridView to implement buttons for selecting all data and deleting data in batches

Jun 15, 2018 pm 04:45 PM
yii yii2 select all batch

This article mainly introduces the example of using GridView to implement all data selection and batch deletion buttons in yii2. It has certain reference value. Those who are interested can learn more.

After sorting through the documents, I found an example of using GridView to implement all-data selection and batch deletion buttons. I sorted it out a bit and simplified it for sharing.

Let’s first look at the effect of implementation

The key code is as follows:

  <?= GridView::widget([
   &#39;dataProvider&#39; => $dataProvider,
   &#39;showFooter&#39; => true, //设置显示最下面的footer
    &#39;id&#39; => &#39;grid&#39;,
    &#39;columns&#39; => [
     [
      &#39;class&#39;=>CheckboxColumn::className(),
      &#39;name&#39;=>&#39;id&#39;,
      &#39;headerOptions&#39; => [&#39;width&#39;=>&#39;30&#39;],
      &#39;footer&#39; => &#39;<button href="#" rel="external nofollow" class="btn btn-default btn-xs btn-delete" url="&#39;. Url::toRoute(&#39;admin/delete&#39;) .&#39;">删除</button>&#39;,
      &#39;footerOptions&#39; => [&#39;colspan&#39; => 5],
     ],
     [&#39;attribute&#39; => &#39;id&#39;, &#39;footerOptions&#39; => [&#39;class&#39;=>&#39;hide&#39;]], //其他列每个都要增加footerOptions项,设置class为hide,到达隐藏效果;
     [&#39;attribute&#39; => &#39;username&#39;, &#39;footerOptions&#39; => [&#39;class&#39;=>&#39;hide&#39;]],
     [
      &#39;attribute&#39; => &#39;status&#39;,
      &#39;value&#39; => function($model){
       if ($model->status == Admin::STATUS_ACTIVE){
        return &#39;启用&#39;;
       }
       return &#39;禁用&#39;;
      },
      &#39;footerOptions&#39; => [&#39;class&#39;=>&#39;hide&#39;]
     ],
     [&#39;class&#39; => &#39;yii\grid\ActionColumn&#39;, &#39;header&#39; => &#39;管理操作&#39;, &#39;footerOptions&#39; => [&#39;class&#39;=>&#39;hide&#39;]],
    ],
   &#39;layout&#39; => "{items}\n{pager}"
  ]); ?>
Copy after login

Getting the final selected data:

var ids = $("#grid").yiiGridView("getSelectedRows");
Copy after login

After getting the data, you can ajax submit it to the desired controller

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

yii2 implements paging and paging with search functions

About how to write search paging jQuery in the YII framework

The above is the detailed content of Yii2 uses GridView to implement buttons for selecting all data and deleting data in batches. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to batch rename file suffixes in win10 How to batch rename file suffixes in win10 Jul 06, 2023 pm 07:37 PM

How to batch rename file suffixes in win10? Nowadays, many users are using the Win10 system, and when we usually use computers, we often use a lot of shortcut keys, because shortcut keys can make our operations more convenient, so how do we rename files in batches? Below, the editor will introduce to you the operation of batch renaming files in Win10. How to batch rename files in Win10 1. Select all the files you want to rename. 2. Right-click on a selected file and select Rename. 3. After a file is renamed, other files will be marked with serial numbers in turn. The method is very simple, but when modifying, you need to pay attention to the order of the files and the sorting position of the modified sample files. The serial number starts from the modified sample file.

How to remove jquery in yii2 How to remove jquery in yii2 Feb 17, 2023 am 09:55 AM

How to remove jquery from yii2: 1. Edit the AppAsset.php file and comment out the "yii\web\YiiAsset" value in the variable $depends; 2. Edit the main.php file and add the configuration "'yii" under the field "components" \web\JqueryAsset' => ['js' => [],'sourcePath' => null,]," to remove the jquery script.

How to use PHP framework Yii to develop a highly available cloud backup system How to use PHP framework Yii to develop a highly available cloud backup system Jun 27, 2023 am 09:04 AM

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

Symfony vs Yii2: Which framework is better for developing large-scale web applications? Symfony vs Yii2: Which framework is better for developing large-scale web applications? Jun 19, 2023 am 10:57 AM

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

How to use Yii3 framework in php? How to use Yii3 framework in php? May 31, 2023 pm 10:42 PM

As the Internet continues to develop, the demand for web application development is also getting higher and higher. For developers, developing applications requires a stable, efficient, and powerful framework, which can improve development efficiency. Yii is a leading high-performance PHP framework that provides rich features and good performance. Yii3 is the next generation version of the Yii framework, which further optimizes performance and code quality based on Yii2. In this article, we will introduce how to use Yii3 framework to develop PHP applications.

Data query in Yii framework: access data efficiently Data query in Yii framework: access data efficiently Jun 21, 2023 am 11:22 AM

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Yii2 vs Phalcon: Which framework is better for developing graphics rendering applications? Jun 19, 2023 am 08:09 AM

In the current information age, big data, artificial intelligence, cloud computing and other technologies have become the focus of major enterprises. Among these technologies, graphics card rendering technology, as a high-performance graphics processing technology, has received more and more attention. Graphics card rendering technology is widely used in game development, film and television special effects, engineering modeling and other fields. For developers, choosing a framework that suits their projects is a very important decision. Among current languages, PHP is a very dynamic language. Some excellent PHP frameworks such as Yii2, Ph

How to implement the select all/unselect all function in JavaScript? How to implement the select all/unselect all function in JavaScript? Oct 16, 2023 am 09:28 AM

How to implement the select all/unselect all function in JavaScript? When developing web pages, you often encounter the need to select or unselect multiple check boxes. This requirement is very common in scenarios such as data lists and forms. The select all/unselect all function can be easily implemented using JavaScript. Specific code examples are described below. First, we need an HTML page to demonstrate this functionality. The following is a basic HTML structure: &lt;!DOCT

See all articles