SelGridView extends CGridView with following features:
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).
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):
var selected = $("#mygrid").selGridView("getAllSelection");
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:
table.table tr.selected td, table.table tr.selected:hover td { background: none repeat scroll 0 0 #BCE774; }
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:
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)
Mar 16, 2012
Feb 25, 2012
Added support of CArrayDataProvider
Feb 24, 2012
Initial release
Total 20 comments
Really Good extension with very detailed description.
It's great that the code works for you.
Regards.
Works like charm :-)
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
Books _form.php
Books controller, in actionCreate:
I hope it will be helpful.
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.
hi, yes it was a bug.
Fixed in 2.3 version. Thanks!
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?
Ah.. I had version 2.0 of this extension, no wonder I could not see that method in the JS. Thanks.
yes:
$("#grid2").selGridView("clearAllSelection");
Hey, I really love this plugin to remember the checkboxes, however, is there a way to unselect them all and "forget" what was checked?
answered in PM.
Good morning.
The problem is AJAX post, no SelGridView.
With the code as I have the actionCreate isn't launched.
If I put
in CActiveForm configuration, ToMedicamentos data is saved but no data from the SelGridView.
Could it be that I have to put a button type different from submitButton?
I don't understand why it fails.
Thanks.
PD.:
Here is my ToMedicamentos/actionCreate:
Notice that I created one new ToMedicamentos model called $modelito and one TvPactivosMedicamentos called $modelMPA. When I press submitButton, $modelMedicamentos ,$modelito and $modelMPA are saved in database, but
doesn't work.
selectedItems and ToMedicamentos sent by AJAX are empty. That is, AJAX does not send data. Why?
Furthermore,
Doesn't work.
maybe textfield value missing in ajax data?
Anyway, if you see correct
alert(selected.length)it's not a selgridview issue, try to comment all selgridview parts and submit textfireld only. hth****views/toMedicamentos/_form.php****
ToMedicamentosController.php__
When I press submit button, I want to send $_POST['selectedItems'] and $_POST['ToMedicamentos'] to create action on my controller.
With this code, if I do an "alert(selected [0]);" in my AJAX code, I can show it, but no actionCreate is launched.
Thanks for reply.
lagogz, for me everything looks correct.
1. could you just select 2 rows in grid and run in browser console:
$("#to-pactivos-grid").selGridView("getAllSelection")to see what is actually returned?
2. if possible, please post selgridview widget config.
Please, view my post again.
SelectableRows is OK. I have AJAX pagination, I think.
hi, please check:
selectableRows = 2in grid config ?Good afternoon.
I have a form with a textfield and a selgridview.
I can't save my values for textfield aand selgrdiview.
Can anyone help me?
Tanks.
Or you can do something like this if you'ld like Yii to generate your code (CSRF may need to be added here);
I don't know the best practice, but I did it like this..
On your items controller, on actionMultipleDelete()..
Leave a comment
Please login to leave your comment.