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

  1. Demo
  2. Download
  3. Requirements
  4. Installation
  5. Usage
  6. Usage with bootstrap
  7. How it works
  8. Note
  9. Issues
  10. History

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)

Demo

Try out a demo

Download

Latest version 2.3

Requirements

Tested on Yii 1.1.9.

Installation

Put selgridview folder from zip to your protected/extensions.

Usage

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

Controller:

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,
    'columns'=>array(
        array(
          'class' => 'CCheckBoxColumn',
        ),
        'UserID',
        'UserName',
     ),
  ));
?>

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): ~~~ [javascript] var selected = $("#mygrid").selGridView("getAllSelection"); ~~~

Usage with bootstrap

it is possible to use with bootstrap gridview.

Example:

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

To highlight selected rows in such bootstrap-grid you can add to your css: ~~~ [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

Note

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

Issues

Please submit issues to github. Thanks for feedback!

History

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

16 0
39 followers
1 220 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: Vitalets
Created on: Feb 24, 2012
Last updated: 11 years ago

Related Extensions