title: Bulk action in yii Grid View
body: <p>I am new to Yii. I need to have a bulk action like bulk delete in CGrid view. I tried by doing in javascript and performing the action using AJAX call. But I dont get what I needed. Please help me solve this.
  My view:</p>
  
  <pre><code>&lt;?php $details=$details;
      ?&gt;
      &lt;h3&gt;&lt;?php echo $name; ?&gt;&lt;/h3&gt;
      &lt;div id="content" style="margin: 0"&gt;
      &lt;?php $form=$this-&gt;beginWidget('CActiveForm', array(
          'id'=&gt;'nimsoft-host-form',
          //'enableAjaxValidation'=&gt;true,
              'enableClientValidation' =&gt; true,
              'clientOptions' =&gt; array(
                  'validateOnSubmit' =&gt; true,
                  'validateOnChange' =&gt; true, // allow client validation for every field
               ), 
              'htmlOptions' =&gt; array('enctype' =&gt; 'multipart/form-data'),
      )); ?&gt;
              &lt;?php $this-&gt;endWidget();?&gt;
          &lt;h3&gt;&lt;?php echo htmlspecialchars($title); ?&gt;&lt;/h3&gt;
          &lt;h3&gt;&lt;?php echo $title; ?&gt;&lt;/h3&gt;
         &lt;div style="padding: 10px;"&gt;
              &lt;a href="&lt;?php echo $this-&gt;createUrl('/Nimsoft/create?id='.$details-&gt;host_customer_id);?&gt;" title="Create New Host" class="btn btn-primary circle_ok" style="text-decoration: none;" &gt;Add New Host to Customer&lt;/a&gt;
              &lt;a href="&lt;?php echo $this-&gt;createUrl('/Nimsoft/Search_all?id='.$details-&gt;host_customer_id);?&gt;" title="View All Hosts" class="btn btn-primary circle_ok" style="text-decoration: none;" &gt;View All Hosts&lt;/a&gt;
              &lt;a href="&lt;?php echo $this-&gt;createUrl('/Nimsoft/Search_all',array('id'=&gt;$details-&gt;host_customer_id,'isXLSDownload'=&gt;1));?&gt;" title="Export" class="btn btn-primary circle_ok" style="text-decoration: none;" &gt;Export&lt;/a&gt;
              &lt;a href="&lt;?php echo $this-&gt;createUrl('/Nimsoft/Search_all',array('id'=&gt;$details-&gt;host_customer_id,'isXLSDownload'=&gt;2));?&gt;" title="Export For All Customers" class="btn btn-primary circle_ok" style="text-decoration: none;" &gt;Export For All Customers&lt;/a&gt;
              &lt;div style="float:right"&gt;
                               &lt;?php
                              echo CHtml::link('Upload Customer CSV', array('/Nimsoft/uploadCustomers?id='.$details-&gt;host_customer_id), array(
                                  'onclick'=&gt;'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size", align: "center" } )',
                                  'class'=&gt;'btn btn-primary',
                                  'id'=&gt;'upload_link',
                                  ));
                               ?&gt;                          
                           &lt;/div&gt;
              &amp;nbsp;&amp;nbsp;&lt;?php //echo CHtml::Button('Export CSV', array('class' =&gt; 'btn btn-primary circle_ok exportCSV-button')); 
              echo '&lt;form method="post" name="exportCSV-form" id="exportCSV-form" action="' . yii::app()-&gt;createUrl('/export/exportCSV') . '"&gt;';
                      echo '&lt;input type="hidden" name="filename" value="HostName"&gt;';
                      $this-&gt;renderPartial('_export_list', array(
                          'model' =&gt; $model,
                      ));
                      echo '&lt;/form&gt;';
                      ?&gt;
  
  
  
          &lt;div class="innerLR"&gt;
              &lt;div class="row-fluid"&gt;
                 &lt;?php 
                 Yii::app()-&gt;clientScript-&gt;registerScript('search_inc', "
                          $('.exportCSV-button').click(function() {
                              $.fn.yiiListView.update('exportListView', {
                                  data: $('#search-pm-form').serialize() + '&amp;export=true',
                                  complete: function() {
                                      $('#exportCSV-form').submit();
                                  }
                              });
                          }); 
                          ");?&gt;
                  &lt;?php
      echo CHtml::button("Add Date Entries",array("id"=&gt;"butt"));
      ?&gt;
      &lt;?php 
      $obj=$this-&gt;widget('bootstrap.widgets.TbExtendedGridView', array(
          'id'=&gt;'yiisession-grid',//'host_grid',
          'dataProvider'=&gt;$dataProvider,
          'type' =&gt; 'striped bordered',
          'columns'=&gt;array(
                                      array(
                                      'id' =&gt; 'selectedIds',
                                      'class' =&gt; 'CCheckBoxColumn',
                                          'selectableRows'=&gt;2,
                                  ),
  
                      array(            // display 'create_time' using an expression
                                  'name'=&gt;'host_name',
                                          'value'=&gt;'$data-&gt;host_name',
                      ),
                      array(
                                  'name'=&gt;'host_serviceid',
                                  'value'=&gt;'$data-&gt;host_serviceid',
                      ),
                                      array(
                                  'name'=&gt;'status',
                                  'value'=&gt;'$data-&gt;status',
                      ),
                      array(
                                          'class'=&gt;'CButtonColumn',
                                          'template'=&gt;'{edit_date}{update}{delete}',
                                          'htmlOptions'=&gt;array('width'=&gt;'95px'),
                                          'buttons' =&gt; array(
                                                 'edit_date' =&gt; array( //the name {reply} must be same
                                                   'label' =&gt; 'Add Date', // text label of the button
                                                     'url' =&gt; 'Yii::app()-&gt;createAbsoluteUrl("NimsoftHostsDetails/View", array("id"=&gt;$data-&gt;host_id))', 
                                                        'imageUrl' =&gt; Yii::app()-&gt;baseUrl.'/images/icons/pencil.png',  // image URL of the button. If not set or false, a text link is used, The image must be 16X16 pixels
  
                                                     ),
                                                 ),)
  
                      ),
  
  
      ))
              ; 
  
      ?&gt;
  
         &lt;/div&gt;
  
      &lt;html lang="en"&gt;
      &lt;head&gt;
        &lt;meta charset="utf-8"&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  
              &lt;div class="separator bottom"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="clearfix"&gt;&lt;/div&gt;
      &lt;div id="footer" class="hidden-print"&gt;
      &lt;?php $this-&gt;renderPartial('application.views.layouts._footer_inc');  ?&gt;
      &lt;/div&gt;
      &lt;/div&gt;
      &lt;script&gt;
              hs.preserveContent = false;
              hs.dimmingOpacity = 0.75;
              hs.zIndexCounter = 10000;
              hs.showCredits = false;
  
              // this will disable close when we click on other area than close button
              hs.onDimmerClick = function() {
                  return false;
              }
  
          $('.exportCSV-button').click(function() {
                  $.fn.yiiListView.update('exportListView', {
                      data: $('#search-faq-form').serialize() + '&amp;export=true',
                      complete: function() {
                          $('#exportCSV-form').submit();
                      }
                  });
          }); 
  
      &lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
          var gridId = "yiisession-grid";
  
          $(function(){
              $(document).on('click','#yiisession-grid a.bulk-action',function() {
                  return false;
              });
          });
          function batchActions(values){
              var url = $(this).attr('Nimsoft/select_all');
              var ids = new Array();
              if(values.size()&gt;0){
                  values.each(function(idx){
                      ids.push($(this).val());
                  });
                  $.ajax({
                      type: "POST",
                      url: url,
                      data: {"ids":ids},
                      dataType:'json',
                      success: function(resp){
                          //alert( "Data Saved: " + resp);
                          if(resp.status == "success"){
                             $.fn.yiiGridView.update(gridId);
                          }else{
                              alert(resp.msg);
                          }
                      }
                  });
              }
          }
      &lt;/script&gt;
  
      &lt;?php
      Yii::app()-&gt;clientScript-&gt;registerScript('edit_date','
      $("#butt").click(function(){
              var checked=$("#host_grid").yiiGridView("getChecked","host_grid_c1");
              var count=checked.length;
              if(count&gt;0 &amp;&amp; confirm("Do you want to delete these "+count+" item(s)"))
              {
                      $.ajax({
                              data:{checked:checked},
                              url:"'.CHtml::normalizeUrl(array('item/remove')).'",
                              success:function(data){$("#host_grid").yiiGridView("update",{});},              
                      });
              }
              });
      ');
  
  
      ?&gt;
  </code></pre>
  
  <p>My Bulk action code is not working. Please correct me where I went wrong. Thanks in advance.</p>