Yii 1.1: selgridview

Remembers selected rows when sorting or paging and allows to select row programmatically

SelGridView extends CGridView with following features:

  • remember selected rows on sorting / paging grid
  • select rows programmatically by GET param (e.g. to highlight new record, etc)


Try out a demo


Latest version 2.3


Tested on Yii 1.1.9.


Put selgridview folder from zip to your protected/extensions.


Use as standart CGridView widget (don't forget to set selectableRows >= 1).


public function actionIndex()
    $dataProvider = new CActiveDataProvider('User', array(
           'pagination' => array(
                'pageSize' => 2,
    $this->render('index', compact('dataProvider'));              

View index.php:

  $this->widget('ext.selgridview.SelGridView', array(
    'id' => 'mygrid',
    'dataProvider' => $dataProvider,
    'selectableRows' => 2,
          'class' => 'CCheckBoxColumn',

When sorting or paging such grid, you will see in ajax GET params "User_sel={id}" as well as "User_page={page}". Value of User_sel is model primaryKey. Widget automatically proceess this value and select rows.

If you want to highlight newly created row in grid you need to set GET param User_sel={new-record-id}:

$this->createUrl('user/index', array('User_sel' => 123));

To get all selected keys on all pages in your javascript (when selectableRows >= 2):

var selected = $("#mygrid").selGridView("getAllSelection");

Usage with bootstrap

it is possible to use with bootstrap gridview.


$this->widget('ext.selgridview.BootSelGridView', array(
    'id' => 'mygrid',
    'dataProvider' => $dataProvider,

To highlight selected rows in such bootstrap-grid you can add to your css:

table.table tr.selected td, table.table tr.selected:hover td {
    background: none repeat scroll 0 0 #BCE774;

How it works

Standart CGridView can automatically select rows in grid when there is checkox column with checked = true values. But it does not keep selection on sorting / paging. This extension makes two things:

  • creates hidden CCheckBoxColumn that gets checked by GET param. If there is checkbox column in widget config, no hidden column generated
  • attach BeforeAjaxUpdate js function that adds GET params to URL when sorting and pagination


When you have selectableRows > 1 SelGridview will remember all selected rows on all grid pages not only on visible page.


Please submit issues to github. Thanks for feedback!


Mar 21, 2012
Added support of BootGridView

Mar 18, 2012 (version 2.0)

  • widget significally rewriten with javascript, code became more clear
  • added JS method for getting all selected keys from all pages (comment #7371)

Mar 16, 2012

  • fixed #7346 (thanks to horacio.segura)
  • added support for several grids on one page
  • improved demo

Feb 25, 2012
Added support of CArrayDataProvider

Feb 24, 2012
Initial release

Total 20 comments

#19219 report it
le_top at 2015/04/23 03:44am
URL rewrite


The issue is beyond 'selgridview's code. I reported this behavior on the forums: http://www.yiiframework.com/forum/index.php/topic/61761-yii-11-cgridview-curlmanager-breaks-filtering/ I am not reporting anything as a bug anymore as in +95% of the cases they are not considered as bugs. So I just report a behavior - up to the reader to decide if it merits a change or not.

I plan on digging into a specialisation for my use cases - when I find enough time. A first method could be to detect that '_page' is amongst the parameters and avoid the rewriterule in that case.

#19218 report it
Todd Anstis at 2015/04/23 02:36am
URL Rewrite

My GET parameters are being rewritten so I'm getting a "Forbidden" error:


Any tips on excluding this URL from URL rewrite rules?

#17630 report it
datdit at 2014/07/09 07:52am
Thank you very much.

it's work very well for me.

#17107 report it
MarkBrass at 2014/05/04 08:22am
Is it limitied to 98 rows?

The extension is working great.

BUT , I have 220 rows , and selGrid is saving only up to 98.

Does it have to do something with the URL's length?

#16975 report it
Bjorn at 2014/04/17 09:32am
Disable rows

I use this extension and I'm happy with it.

The only thing I wish I have is that it's possible to exclude rows from selection. I have added a checkbox for every row, but even when I make it 'disabled', it's still possible to select it when I tick the row or the checkbox in the header column.

          'class' => 'CCheckBoxColumn',
#16590 report it
Vinod Agarwal at 2014/03/09 01:34am
Unable to select more than 300 contacts

Hi, I am facing an issue as I am not able to select more than 300 records due to $_GET parameter limit. So if there are any method by which I can select as many contacts as per requirment.

#16440 report it
selorm at 2014/02/23 09:52am
nice work...a suggestion

Heyy! nice work there..just to add up, you could change line 40 of SelGridView.php to;

$this->selBaseScriptUrl = Yii::app()->getAssetManager()->publish(dirname(__FILE__).'/assets');

in order to allow placing the extension somewhere else aside protected/extensions folder. For e.g, i have frontend, common and backend as my folder structure and i placed extension inside common, it threw error of not able to locate the assets folder. Hope this helps -:)

#16383 report it
mrs at 2014/02/17 08:01am
How do I submit all selected rows?

How do I submit all selected rows from different pages? I have found it's only submitting selected rows from active page. In browser console I have found it's generating URL with all selected rows.

Is there any way that can help me to submit form with all selected rows from different pages?

Thanks in advance

#13633 report it
Rodrigo Coelho at 2013/06/12 09:44pm

Great extension, Vitalets. It works very well :)

#12652 report it
karmraj at 2013/04/04 01:36am
Awesome extension !!!!

Really Good extension with very detailed description.

#11938 report it
lagogz at 2013/02/13 05:53pm
I'm very pleased

It's great that the code works for you.


#11932 report it
zvik2004 at 2013/02/13 12:48pm
lagogz, thank you very much

Works like charm :-)

#11921 report it
lagogz at 2013/02/13 02:30am
Zvi, I do the following

Good morning all!

Suppose I have 3 tables:

Authors: AuthorId, Name

Books: BookId, Title

Authors_Books: AuthorId, BookId

A book can have multiple authors.

Then, when I add a new book, I want to select multiple authors in SelGridView and save data.

model Books

public $Authors; //I build this property that have authors ids separated by commas.
public function rules()
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
                    array('Authors', 'required'),

Books _form.php

    function selAuthors()
        var arraySel = $("#to-authors-grid").selGridView("getAllSelection");
        var stringSel=arraySel.join(',');                                                                          
        $('#Books_Authors').val(stringSel);//#Books_Authors is hidden field id.
//This hidden field will have authors ids separated by commas.
<div class="row">
                echo $form->hiddenField($modelBooks,'Authors');
                echo $form->error($modelBooks,'Authors'); 
//in SelGridView widget.

Books controller, in actionCreate:

$Authors=explode(',',$modelBooks->Authors);//Make an authors array.
                    foreach ($Authors as $IdAuthor)
                        //Save relation data.

I hope it will be helpful.

#11909 report it
zvik2004 at 2013/02/12 05:00pm
Problem when working with a form

Hi, I have a form and a table in it. If I select a row, and then move to the next page (so that the selected row can't be seen), and then press on the submit button, I get nothing in the selected rows. Note that: 1. I work with bootstrap (ext.selgridview.BootSelGridView) 2. I get the selected rows from the _POST parameters.

Thanks, Zvi.

#11795 report it
Vitalets at 2013/02/04 09:18am
Re: The clearing selection

hi, yes it was a bug.
Fixed in 2.3 version. Thanks!

#11772 report it
rclai89 at 2013/02/02 06:21pm
The clearing selection

Hey, I noticed that when I use selGridView("clearAllSelection"), the checkboxes of the current page are unchecked, but the other pages with checkboxes checked do not get unchecked. Is that a bug?

#11771 report it
rclai89 at 2013/02/02 06:14pm

Ah.. I had version 2.0 of this extension, no wonder I could not see that method in the JS. Thanks.

#11762 report it
Vitalets at 2013/02/02 04:17am
Re: Ability to uncheck all?


#11759 report it
rclai89 at 2013/02/01 11:05pm
Ability to uncheck all?

Hey, I really love this plugin to remember the checkboxes, however, is there a way to unselect them all and "forget" what was checked?

#11597 report it
Vitalets at 2013/01/22 10:51am
Re: I still have the problem.

answered in PM.

Leave a comment

Please to leave your comment.

Create extension
No downloadable files yet