Skip to content

gridview.js getChecked seems not to work #1225

Closed
giannisdag opened this Issue Aug 14, 2012 · 7 comments

4 participants

@giannisdag

I have tested the gridview.js getChecked to get all the checked rows, but it was not working. I have changed the following line,

this.children('.' + settings.tableClass).children('tbody').children('tr').children('td'). 

to this

this.find('.' + settings.tableClass).children('tbody').children('tr').children('td').

and now it works fine. It's my first time using github and sorry if I made anything wrong

@mdomba mdomba was assigned Aug 14, 2012
@mdomba
Yii Software LLC member
mdomba commented Aug 14, 2012

Please write the code you used to test getChecked().

@giannisdag

this is the gridView

<?php
    $this->widget('bootstrap.widgets.TbGridView', array(
    'id'=>'searchPlayers-grid',
    'dataProvider'=>$playerDataProvider,
    'selectableRows'=>2,
    'itemsCssClass'=>'table table-striped table-bordered table-condensed',
    'columns'=>array(
    array('name'=>'userid', 'header'=>'#'),
    'fullname',
    array(
    'class'=>'CCheckBoxColumn',
                'id'=>'setPlayersBtn',
    ),
    )));
?>

This is the ajax submit button

<?php echo CHtml::ajaxSubmitButton('Submit players',CHtml::normalizeUrl(array('team/setPlayers')),
array(
 'data' => 'js:{theIds : $.fn.yiiGridView.getChecked("searchPlayers-grid","setPlayersBtn").toString(), playersIds : getPlayersGrid("","#players-grid","#playersIds").toString()}',
 'success'=> 'function(html){$("#players-grid").html(html);$("#modalAddPlayers").modal("hide");}',
),
array(
'class'=>'btn btn-primary'
)
); ?>

I have changed the line 352

            this.children('.' + settings.tableClass).children('tbody').children('tr').children('td').children('input[name="' + column_id + '"]').each(function (i) {
to this
            this.find('.' + settings.tableClass).children('tbody').children('tr').children('td').children('input[name="' + column_id + '"]').each(function (i) {

I am using the yii bootstrap extension, but the problem remained even if I used the original gridview

@creocoder

Please use markdown next time to properly format source codes.

@samdark
Yii Software LLC member
samdark commented Aug 14, 2012

Updated source code.

@mdomba
Yii Software LLC member
mdomba commented Aug 14, 2012

I'm trying your code but it works for me and should work with children as ".items" is the children of the grid....
Two things I noticed in your code, first is that you are not using the standard CGridView but an extended class and the checkboxcolumn example seems incomplete as it needs a value or a name to be working.

@giannisdag

I checked again, and found where the problem is, I thought it had disappeared after upgrading to yii 1.1.11, I had wrote about this in the forum,
http://www.yiiframework.com/forum/index.php/topic/34373-gridview-in-renderpartial-dublicates-its-id-name-after-ajax-post/page__p__165413#entry165413
but I was wrong, sorry for this.
The grid view is being created twice, or else the first grid view which is created in render partial is never disappeared, so the getChecked function is not working. I don't know why this happens, I have to check it out.

Also I have to make 2 comments
1)the checkboxcolumn seems to work just right without setting a value or a name, just an id. This id seems to be the name, and also this column id is passed as parameter to the function getChecked.
2)If you check, you will see that getChecked and getSelection follow the same logic, but getSelection uses in the beginning of jquery the find method. I cannot understand why you didn't use the same method for both functions.
Sorry again

@giannisdag giannisdag closed this Aug 14, 2012
@mdomba
Yii Software LLC member
mdomba commented Aug 14, 2012

1 - yes you are right, I mixed this with a custom CCheckBox extension
2 - children() gets only the first level child's of an element while find() gets all the child's (any level deep)

getSelection() was changed because of the issue #769, and as you pointed getSelection() and getChecked follows the same logic so even getChecked should be changed as it would not work with a custom template

@mdomba mdomba added a commit that referenced this issue Aug 14, 2012
@mdomba mdomba (Fixes #1225, #769) yiiGridView.js getChecked() was not working if cu…
…stom template was used
63ffca0
@mdomba mdomba added a commit that referenced this issue Aug 14, 2012
@mdomba mdomba changelog for #1225 253b08d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.