GridView 全选可以吗?

GridView 全选可以吗?

sure.you can see CCheckBoxColumn


$this->widget('zii.widgets.CGridView', array(

   ...

   'columns'=>array(

       array(

             'class'=>'CCheckBoxColumn',

             'id'=>'id', 

             'selectableRows'=>2, 

       ),

cute,可是我想选中后☑怎么做个按钮的jquery事件删除掉所选的呢

I solved it :lol:

    <script type="text/javascript">

/<![CDATA[/

var GetCheckbox = function (){

    var data=new Array();


    &#036;(&quot;input[name='selectdel[]']:checked&quot;).each(function (){


           // if(&#036;(this).attr(&quot;checked&quot;)==true){


                    data.push(&#036;(this).val());


           // }


    });


    if(data.length &gt; 0){


            &#036;.post('&lt;?php echo CHtml::normalizeUrl(array('DelSelect'));?&gt;',{'selectdel[]':data},


            		function(){window.location.reload();}


    			);





    }else{


            alert(&quot;请选择要删除的内容&#33;&quot;);


    }

}

/]]>/

</script>

<?php $this->widget(‘zii.widgets.grid.CGridView’, array(

'id'=&gt;'leave-grid',


'dataProvider'=&gt;&#036;model-&gt;search_username(),


//'filter'=&gt;&#036;model,


'columns'=&gt;array(


    array(


         'id'=&gt;'id', 


         'class'=&gt;'CCheckBoxColumn',            


         'selectableRows'=&gt;2, 


         'footer'=&gt;'&lt;button type=&quot;button&quot; onclick=&quot;GetCheckbox();&quot; style=&quot;width:76px&quot;&gt;批量删除&lt;/button&gt;',


         'headerHtmlOptions' =&gt; array('width'=&gt;'33px'),


         'checkBoxHtmlOptions' =&gt; array('name' =&gt; 'selectdel[]'),	 


		 'htmlOptions'=&gt;array(    


						'style'=&gt;'text-align:center',


		        )


            ),


	'date',


	'type'=&gt;array(


       'name'=&gt;&quot;类型&quot;,


       'value'=&gt;'(&#036;data-&gt;type==1)?&quot;上午&quot;<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />(&#036;data-&gt;type==2)?&quot;下午&quot;:&quot;整天&quot;)',


	),


	'reasons',


	'username',


    'pass'=&gt;array(


        'name'=&gt;'审核结果',


		'type'=&gt;'html',			


       // 'value'=&gt;'((&#036;data-&gt;pass==1)?&quot;通过:&quot;审核中&quot;)',


		'value'=&gt;'(&#036;data-&gt;pass)?&quot;&lt;img  src=&#092;&quot;images/passed.jpg&#092;&quot; alt=&#092;&quot;通过&#092;&quot; width=&#092;&quot;15&#092;&quot; height=&#092;&quot;15&#092;&quot;&gt;&quot;:&quot;&lt;img  src=&#092;&quot;images/ing.gif&#092;&quot; alt=&#092;&quot;审核中&#092;&quot;&gt;&quot;',


		'htmlOptions'=&gt;array(    


        'style'=&gt;'text-align:center',


           )


	


  	 ), 


 


	array(


	    'header'=&gt;'操作',


		'class'=&gt;'CButtonColumn',


	),


),


)

); ?>

controller~~~

public function actionDelSelect()

        {


                if (Yii::app()-&gt;request-&gt;isPostRequest)


                {


                        &#036;criteria= new CDbCriteria;


                        &#036;criteria-&gt;addInCondition('id', &#036;_POST['selectdel']);


                        Leave::model()-&gt;deleteAll(&#036;criteria);


                       


                        if(isset(Yii::app()-&gt;request-&gt;isAjaxRequest)) {


                                echo CJSON::encode(array('success' =&gt; true));


                                &#036;this-&gt;redirect(array('/leave/admin'));  


                        } else


                             &#036;this-&gt;redirect(array('/leave/admin'));  


                        	// &#036;this-&gt;redirect(isset(&#036;_POST['returnUrl']) ? &#036;_POST['returnUrl'] : array('index'));


                }


                else


                        throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');


                


        }

mark

:unsure:做个记号,需要的时候来取!

mark

mark

在view中写过多的处理不便于代码复用, 比较好的解决办法是在gridview外面套一个cactiveform.

怎么个套法?

标记下