Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select all record of all page in checkbox column of gridview yii2

I wants to know if there is any inbuilt option in yii2 gridview checkbox column to select/deselect all rows at once..

For example if i have 500 records in a gridview and i am displaying 100 records at once than i can only select 100 records at once and do any bulk action.

I want user to be able to select all 500 records at once and do any bulk action with those record at once.. hope you all get my question

I made a suggestion to yii framework owners on github and they have confirmed that they will do this enhancement soon enough and put this issue in enhancement section, so hoping that they will include it soon enough but until then guide me to achieve this in any alternate way

Thank you

like image 796
Mike Ross Avatar asked Oct 18 '15 23:10

Mike Ross


1 Answers

Yes, You can use CheckBoxColumn. Just add the following lines into your GridView's columns array:

[
     'class' => 'yii\grid\CheckboxColumn',
     'name' => 'id'
],

As Yii2's Official document:

CheckboxColumn displays a column of checkboxes in a grid view. To add a CheckboxColumn to the yii\grid\GridView, add it to the columns configuration as follows:

'columns' => [
// ...
    [
        'class' => 'yii\grid\CheckboxColumn',
        // you may configure additional properties here
    ],
]

Users may click on the checkboxes to select rows of the grid. The selected rows may be obtained by calling the following JavaScript code:

var keys = $('#grid').yiiGridView('getSelectedRows');
// keys is an array consisting of the keys associated with the selected rows
like image 122
Ali MasudianPour Avatar answered Sep 28 '22 01:09

Ali MasudianPour