Rectangle 27 7

You could use sessions/cookies to store the checked values. I'm not very sure how to make cookies work, so i'll tell you how to do it with sessions. Specifically the user session that yii creates.

Now to use sessions we need to pass the checked (and unchecked) ids to the controller, therefore we'll modify the data being sent to the controller on every ajax update(i.e between paginations), to do this we exploit the beforeAjaxUpdate option of CGridView.

I'm also using CCheckBoxColumn instead of the following in your code(of course you can modify the solution to suit your own needs):

array(
     'name' => 'demo',
     'type'=>'raw',
     'header' => "Select",
     'value' => 'CHtml::checkBox("email[]","",array("class"=>"check","value"=>$data->email_id))',
),
<?php $this->widget('zii.widgets.grid.CGridView', array(
    // added id of grid-view for use with $.fn.yiiGridView.getChecked(containerID,columnID)
    'id'=>'first-grid',

    'dataProvider'=>$model->search(),
    'cssFile' => Yii::app()->baseUrl . '/media/js/admin/css/admingridview.css',

    // added this piece of code
    'beforeAjaxUpdate'=>'function(id,options){options.data={checkedIds:$.fn.yiiGridView.getChecked("first-grid","someChecks").toString(),
        uncheckedIds:getUncheckeds()};
        return true;}',

    'ajaxUpdate'=>true,
    'enablePagination' => true,
    'columns' => array(
            array(
                 'name' => 'id',
                 'header' => '#',
                 'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + ($row+1)',
            ),
            array(
                 'name' => 'fb_user_id',
                 'header' => 'FaceBook Id',
                 'value' => 'CHtml::encode($data->fb_user_id)',
            ),
            array(
                 'name' => 'first_name',
                 'header' => 'Name',
                 'value' => 'CHtml::encode($data->first_name)',
            ),
            array(
                 'name' => 'email_id',
                 'header' => 'Email',
                 'value' => 'CHtml::encode($data->email_id)',
            ),

            /* replaced the following with CCheckBoxColumn
              array(
                 'name' => 'demo',
                 'type'=>'raw',
                 'header' => "Select",
                 'value' =>'CHtml::checkBox("email[]","",array("class"=>"check","value"=>$data->email_id))',
              ),
            */

            array(
                 'class' => 'CCheckBoxColumn',
                 'selectableRows' => '2',
                 'header'=>'Selected',
                 'id'=>'someChecks', // need this id for use with $.fn.yiiGridView.getChecked(containerID,columnID)
                 'checked'=>'Yii::app()->user->getState($data->email_id)', // we are using the user session variable to store the checked row values, also considering here that email_ids are unique for your app, it would be best to use any field that is unique in the table
            ),
    ),
));
?>

Pay special attention to the code for beforeAjaxUpdate and CCheckBoxColumn, in beforeAjaxUpdate we are passing checkedIds as a csv string of all the ids(in this case email_ids) that have been checked and uncheckedIds as a csv string of all the unchecked ids, we get the unchecked boxes by calling a function getUncheckeds(), which follows shortly. Please take note here, that when i was testing i had used an integer id field (of my table) as the unique field, and not an email field.

The getUncheckeds() function can be registered like this anywhere in the view file for gridview:

Yii::app()->clientScript->registerScript('getUnchecked', "
       function getUncheckeds(){
            var unch = [];
            /*corrected typo: $('[name^=someChec]') => $('[name^=someChecks]') */
            $('[name^=someChecks]').not(':checked,[name$=all]').each(function(){unch.push($(this).val());});
            return unch.toString();
       }
       "
);

In the above function pay attention to the selectors and each and push function.

With that done, we need to modify the controller/action for this view.

public function actionShowGrid(){
     // some code already existing
     // additional code follows
     if(isset($_GET['checkedIds'])){
          $chkArray=explode(",", $_GET['checkedIds']);
          foreach ($chkArray as $arow){
               Yii::app()->user->setState($arow,1);
          }
     }
     if(isset($_GET['uncheckedIds'])){
          $unchkArray=explode(",", $_GET['uncheckedIds']);
          foreach ($unchkArray as $arownon){
               Yii::app()->user->setState($arownon,0);
          }
     }
     // rest of the code namely render()
}

thanks a lot..will check it ...thanks for ur patience to figure out the solution..

you are welcome, next time give a bounty on such huge questions :). I did say, i'll try, so i did. Anyway, remember the main points, sessions/cookies , beforeAjaxUpdate, and the setState() getState() functions. You can store things in separate session variable instead of the user session, if you wish.

also, in addition to isset you might also want to check for empty

there's also an extension that i came across today, which might be of help: selgridview

php - Retain Checkbox values in Yii gridview pagination - Stack Overfl...

php ajax pagination yii
Rectangle 27 0

The following yii-wiki provides an excellent step-by-step guide for how to use jQuery's "sortable" to make the CGridview's rows sortable: creating-a-jqueryui-sortable-cgridview

php - Yii CGridView - Drag and Select Rows - Stack Overflow

php yii
Rectangle 27 0

it should update the summary automatically did you use

$.fn.yiiGridView.update('grid-name');

php - How to update the yii CGridview summary after deleting a row - S...

php yii cgridview
Rectangle 27 0

Use the Conditional statements like this:

And Call this dataprovider in your GridView data provider.

php - Yii CGridview hide rows - Stack Overflow

php yii cgridview
Rectangle 27 0

in you search add if or switch

in your gridview

php - Yii CGridview hide rows - Stack Overflow

php yii cgridview
Rectangle 27 0

After some hassle I was able to make the row of the cgridview a link and on clicking on the each row calls an AJAX function. Below is the code. May be it is helpful for someone.

selectionChanged did the trick. On clicking any row calls an ajax function and displays each customer's information a div below grid.

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'customer-grid',
'dataProvider'=>$model->search(),
'selectionChanged'=>'js:function(id){
 n = $.fn.yiiGridView.getSelection(id);
 if (n>0){
    $.ajax({
            url: "'.Yii::app()->urlManager->createUrl('customer/view/').'",
            type: "GET",
            data: {"id": parseInt(n)},
            dataType: "html",
            success: function(data) {
            $("#customer-div").html(data);
         }
         });',

    'filter'=>$model,
    'columns'=>array(
    'id',
    array(
                'name'  => 'trading_name',
                'value' => 'CHtml::link($data->trading_name, Yii::app()
                 ->createUrl("customer/view/",array("id"=>$data->primaryKey)))',
                 'type'  => 'raw',
                 'options' => array('ajax' => array('type' => 'get', 'url'=>'js:$(this).attr("href")',
                 'success' => 'js:function(data) { 
                  $("#tab1").html(data);')
                  ),
             ),
    'email',    
    'site_code',

    array(
        'class'=>'CButtonColumn',
    ),

php - Yii - CGridView rows / column values as link and calling ajax fu...

php ajax yii
Rectangle 27 0

<?php
/**
* XColumnWithDeleteLink
*
* Allows to delete column in CGridView column.
*
* @author Arthur Skobara <skobara.arthur@gmail.com>
* @version 0.1
*/
Yii::import('bootstrap.widgets.TbJEditableColumn');

class XColumnWithDeleteLink extends TbJEditableColumn
{
        public $editableCssClass = 'editable-header';
        public $canBeDeleteCssClass = 'can-be-delete';

        public $deleteURL = '/phone/deletecolumn';

        protected $defaultOptions = array(
                'method' => 'POST', // method to use to send edited content (POST or PUT)
                'callback' => null, // Function to run after submitting edited content
                'name' => 'value', // POST parameter name of edited content,
                'id' => null, // POST parameter name of edited div id (if null will be filled with htmlOptions['id'] or $this->id)
                'submitdata' => null, // Extra parameters to send when submitting edited content
                'type' => 'text', // text, textarea or select (or any 3rd party input type)
                'rows' => null, // number of rows if using textarea
                'cols' => null, // number of cols if using textarea
                'height' => '15px', // 'auto', 'none' or height in pixels,
                'width' => '70%', // 'auto', 'none' or width in pixels
                'loadurl' => null, // URL to fetch input content before editing
                'loadtype' => 'GET', // Request type for load url. Should be GET or POST.
                'loadtext' => null, //  Text to display while loading external content.
                'loaddata' => null, // Extra parameters to pass when fetching content before editing.
                'data' => null, // Or content given as paramameter. String or function.
                'indicator' => null, // indicator html to show when saving (will default to assets/img/loading.gif if null)
                'tooltip' => null, // optional tooltip text via title attribute
                'event' => 'click', // jQuery event such as 'click' of 'dblclick'
                'submit' => null, // submit button value, empty means no button
                'cancel' => null, // cancel button value, empty means no button
                'cssclass' => null, // CSS class to apply to input form. 'inherit' to copy from parent.
                'style' => null, //  Style to apply to input form 'inherit' to copy from parent.
                'select' => false, // true or false, when true text is highlighted
                'placeholder' => null, // Placeholder text or html to insert when element is empty.
                'onblur' => null, // 'cancel', 'submit', 'ignore' or function
                'onsubmit' => null, // function(settings, original) { ... } called before submit
                'onreset' => null, // function(settings, original) { ... } called before reset
                'onerror' => null, // function(settings, original, xhr) { ... } called on error
                'ajaxoptions' => null, // jQuery Ajax options. See docs.jquery.com.
                'cancelAttrs' => array('class' => 'btn'), /* custom property */
                'submitAttrs' => array('class' => 'btn'), /* custom property */
                //'mask' => '99/99/9999', /* configuration setting for masked plugin */
                //'dateformat' => 'yyyy/mm/dd', /* you can use this configuration when using the date plugin */
                //'colorformat' => 'rgb' /*  rgb | hex | rgba you can use this parameter when using color picker plugin @see www.eyecon.ro/bootstrap-colorpicker/ */

        );

        public function init()
        {
                parent::init();

                if (!$this->saveURL)
                {
                        $this->saveURL = Yii::app()->getRequest()->requestUri;
                }
                $this->registerCustomClientScript();
        }

        public function renderHeaderCell()
        {
                $this->headerHtmlOptions['id']=$this->id;
                $this->headerHtmlOptions['data-column-name']=$this->name;
                $this->headerHtmlOptions['class']=$this->canBeDeleteCssClass;
                echo CHtml::openTag('th',$this->headerHtmlOptions);
                $this->renderHeaderCellContent();
                echo "</th>";
        }

        protected function renderHeaderCellContent()
        {
                $sort = $this->grid->dataProvider->getSort();
                $label = isset($this->header) ? $this->header : $sort->resolveLabel($this->name);

                echo "<span class=\"{$this->editableCssClass}\">". $label .'</span><i class="right icon-trash"></i>';
        }

        public function registerCustomClientScript()
        {
                $cs = Yii::app()->getClientScript();
                $assetsUrl = Yii::app()->bootstrap->getAssetsUrl();
                $cs->registerScriptFile($assetsUrl . '/js/jquery.jeditable.js', CClientScript::POS_END);

                $deleteURL = Yii::app()->createUrl($this->deleteURL);

                $options = CJavaScript::encode(array_filter($this->defaultOptions));
                $cs->registerScript(__CLASS__ . '#' . $this->id, "
                        jQuery(document).on('{$this->event}','.{$this->editableCssClass}', function(){
                                var self = jQuery(this);
                                var name = self.parent().attr('data-column-name');
                                var oldValue = self.html();
                                var options = jQuery.extend(true, {$options}, {});
                                self.editable(function(value, settings) {
                                        selectedId = $(this).attr('id');
                                        $.ajax({
                                                url:'{$this->saveURL}',
                                                data:{
                                                        name:name,
                                                        oldvalue:oldValue,
                                                        editheader:'{$this->id}',
                                                        value:value,
                                                },
                                                type:'post',
                                                success: function(data) {
                                                        self.attr('data-column-name', data);
                                                        var label = $('.inline-input-item label[name=\"'+oldValue+'\"]');
                                                        label.attr('name', value);
                                                        label.html(value);
                                                },
                                        });
                                        return value;
                                }, options);
                        });
                ");

                $cs->registerScript(__CLASS__ . '#column-delete', "
                        $(document).on('click', '.icon-trash', function() {
                                var self = this;
                                var name = $(this).parent().attr('data-column-name');
                                $.ajax({
                                        url:'{$deleteURL}',
                                        data:{name:name},
                                        type:'post',
                                        success: function(data) {
                                                $.fn.yiiGridView.update('{$this->grid->id}');
                                                $('.inline-input-item').each(function(){
                                                        var self = $(this);
                                                        if (self.find('label').attr('name') == name) {
                                                                self.remove();
                                                        }
                                                });
                                        }
                                });
                        });
                ");
        }
}

yii - How to edit the header in a yiibooster gridview? - Stack Overflo...

yii cgridview yii-booster
Rectangle 27 0

$columns[]=array(
/* 'class'=>'CDataColumn', */ /* it's the default */
'header'=>'Challenge',
'type'=>'raw',
'value'=>'($data->player->underChallenge!=1)
    ? CHtml::link("ChalengePlayer", array("player/view", "id"=>$data->player->id))
    : "Under Challenge"',
);

php - Decorate a row or field in Yii CGridView if database shows a cer...

php yii
Rectangle 27 0

Actually you can't do this in simple way. There are 2 options:

thanks alex to answer ,i tried to create a row with javascript but i need to be search and filter in gridview .

php - insert static first row in cgridview yii - Stack Overflow

php gridview yii dataprovider
Rectangle 27 0

Use the same technique below.

<?php 
    $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'accounts-grid',
        'dataProvider'=>$model->search(),
        'filter'=>$model,
        'columns'=>array(
                array(
                        'name'=>'commodityId',
                        'value'=>function($data){
                            return '<input type="Text" value="'.$data-  >commodityId.'" />';
                        }
                        ,
                        'type'=>'raw'
                    ),
    ));
?>

php - yii 1.1 cgridview with form input fields and new row - Stack Ove...

php forms yii cgridview
Rectangle 27 0

No it does not. You have to look at jquery draggable and selectable plugins for that

php - Yii CGridView - Drag and Select Rows - Stack Overflow

php yii
Rectangle 27 0

If you want to change the icon in the header of the table, you will need to override styles for classes (.grid-view table.items th a.desc and .grid-view table.items th a.asc). You can also disable visual styles for the table by specifying an option: 'cssFile'=>false and set custom styles for grid. In order to make the entire string anchor link is likely you will need to insert into each cell of the table with the necessary link url. To do this, add the following description of an array of strings:

'columns'=>array(
    ...
    array(         
       'name'=>'name',
       'value'=>'CHtml::link($data->name, "#myAnchor")',
       'type'=>'html'
    ),
    ...
)

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

php - Yii CGridView customizing column head sort icons and row links -...

php yii
Rectangle 27 0

I am not sure what version of Yii you're working on, but let's try this code

<?php

'columns' => array(
array(
    ...
    'type' => 'html',
    'value'=>'CHtml::tag("a",array("class"=>"your-icon-class", "href"=>"#"))',
),

php - Yii CGridView customizing column head sort icons and row links -...

php yii
Rectangle 27 0

I think I know what the problem is. If you have any javascript or CSS added to the view where your grid lives, they may not be available after the ajaxUpdate. I suggest you re-activate the plugins or extra JS functionality used for drag'n'drop.

'afterAjaxUpdate' => 'function(id,data) { $("[rel=\"tooltip\"]").tooltip(); }',

php - Cannot drag Yii CGridview row after update - Stack Overflow

php yii sortable cgridview
Rectangle 27 0

in your model add public static method for example:

add in your gridview for row:

can you explain this a little bit more?

php - Yii CGridview hide rows - Stack Overflow

php yii cgridview
Rectangle 27 0

I have solved the task by conditioning the CDbCriteria as follows,

php - Yii CGridview hide rows - Stack Overflow

php yii cgridview
Rectangle 27 0

You have to use 'htmlOptions' if you wan to set options.

php - Yii - CGridView rows / column values as link and calling ajax fu...

php ajax yii
Rectangle 27 0

Use the same technique below.

<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'accounts-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
        array(
                'name'=>'commodityId',
                'value'=>function($data){
                    return '<input type="Text" value="'.$data-  >commodityId.'" />';
                }
                ,
                'type'=>'raw'
            ),

php - yii 1.1 cgridview with form input fields and new row - Stack Ove...

php forms yii cgridview
Rectangle 27 0

You must have checkboxes with the name check-boxes[] (Watch the brackets!) in your gridview, the code will check for them.

Also, the code will return an array. Use .length instead of the == "".

php - How can I delete group of rows in yii cgridview? - Stack Overflo...

php yii cgridview
Rectangle 27 0

thanks for help alex but actually i want a row for example i have two columns in my cgridview (id ,country_name) and data is fetched through cactivedataprovider from model but i have to insert static row in that grid view

i have to put 0 and allcountries in column id , country_name respectively

i updated answer, in model method getCountryNameOrStaticStringOrWhatever you can return whatever you need

yes data is static not record in database

php - Create Custom Row in yii Cgridview - Stack Overflow

php activerecord yii cgridview