Let's talk about how yii2-GridView implements list page direct modification of data, talk about yii2-gridview_PHP tutorial

Source: Internet
Author: User
Let's talk about how yii2-GridView implements a list page to directly modify data and talk about yii2-gridview. Let's talk about how to implement yii2-GridView list page direct modification of data, talk about yii2-gridview author: White Wolf Source: www.manks.topyii2_gridview_advanced.html this article copyright to the author, welcome to talk about how to implement yii2-GridView list page direct modification of data, talk about yii2-gridview

Author: White Wolf Source: http://www.manks.top/yii2_gridview_advanced.html this article copyright to the author, welcome to reprint, but without the author's consent must retain this paragraph of the statement, and in the article page clearly given the original connection, otherwise, you are entitled to pursue legal liability.

What does it mean? Let me briefly describe the requirements raised by the mini-editor. you see, the data on your list page, can I just click it on the list and modify it directly? it is too inconvenient for me to click it again. This Nima, do you really want to give her a bang.
This article involves about 6 images. For more information, see the original article.
OK. Let's take a look at how to use the gridview function in yii2 to directly modify the list. it's comprehensive. We try to provide instances for all types of attributes.

Step 1: deploy the yii2-grid first.
Install yii2-grid with composer

composer require kartik-v/yii2-grid "@dev"

If you need to output the Token during the installation process, you need to log on to your github account, get the token value through setting> personal access tokens, and enter your token value, just press enter.
After the module is installed, we configure the module as follows, which must be configured.

'modules' => [   'gridview' =>  [        'class' => '\kartik\grid\Module'    ]];

We mentioned above, we need to first deploy the yii2-grid, download the configuration, we open the view file and refer to the following code to modify your file

// Use yii \ grid \ GridView; // The gridview of yii is blocked here. user: The gridviewuse kartik \ grid \ GridView We just installed;
 False, 'columns '=> [// ......],?>

In the above code, we only need to add an item 'port' => false. you do not need to change the original gridview.

Then we install yii2-editable

composer require kartik-v/yii2-editable "@dev"

After the installation, we introduced editable in the file that just configured the gridview.
Use kartik \ editable \ Editable;
The following figure shows how to modify the textInput type.

You can easily see the editing effect and paste the code directly.

[    'attribute' => 'title',    'class'=>'kartik\grid\EditableColumn',],

But we can also see that it is not very convenient to modify the window. let's take a look at the convenient operation method.

[    'attribute' => 'title',    'class'=>'kartik\grid\EditableColumn',    'editableOptions'=>[        'asPopover' => false,    ],],

You only need to click on the attribute value to be modified to directly modify the attribute value. let's take a look at the problem.

You may find that the width of the edit box is too small and the operation is not very convenient. Will it be better if we change the input to textarea? You can also specify headerOptions for the current cell to set the width. For more information about common gridview operations, see

The image looks a lot better, and you can paste the code directly.

[    'attribute' => 'title',    'class'=>'kartik\grid\EditableColumn',    'editableOptions'=>[        'asPopover' => false,        'inputType'=>\kartik\editable\Editable::INPUT_TEXTAREA,        'options' => [            'rows' => 4,         ],    ],],

Some people are curious to click the two buttons in the figure. one is the reset button, and the other is the application button. The reset is fine and easy to understand. However, why does it mean that the app button is always being processed? Don't worry. from the beginning to the present, we will explain the configuration in view first. In fact, after you click the application button, the backend is asynchronously requested.

What if your column is numeric? Simply modify the input directly. if you want the following effects, you need to continue to use composer to install the touch spin widget.

require kartik-v/yii2-widget-touchspin "@dev"

After the installation is complete, let's take a look at how the numeric type attributes are modified.

Third, for the change in the drop-down box, we assume that the is_delete value of the field 1 shows 2 deleted and the data inventory value is 1 2. then, let's paste the code.

Continue reading

Author: White Wolf Source: http://www.manks.top/yii2_gridview_advanced.html文, welcome...

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.