weixin_33749242 2014-03-12 11:46 采纳率: 0%
浏览 48

Yii CgridView批量删除

In many of my Models' CgridViews I have a bulk delete function: a chechboxColumn and a delete button which deletes all the checked users. For that I am using ajax in the admin and a new action in the controller.

All this works fine until I add pagination to th gridview, which is not saving the checked rows in the previous pages.

I tried to use 'enableHistory'=true, but it did nothing (and from what I'v read I'm not the only one :mellow: ) , so I downloaded this extension: selgridview

The extension works - when I move through the pages , the checked rows stay checked BUT , my bulk delete function is seeing only the checked rows of the page I'm in right now.

this is the ajax I'm using:

        <?php
    Yii::app()->clientScript->registerScript('delete','
    $("#butt").click(function(){
                    var checked=$("#person-grid").yiiGridView("getChecked","person-grid_c11");
                    var count=checked.length;
                    if(count>0 && confirm(" are you sure you want to delete "+count+" people ? "))
                    {
                                    $.ajax({
                                                    data:{checked:checked},
                                                    url:"'.CHtml::normalizeUrl(array('person/remove')).'",
                                                    success:function(data){$("#person-grid").yiiGridView("update",{});},              
                                    });
                    }
                    });
    ');
    ?>

Now , maybe thats a silly question but I know little about javascript. I'm not even sure that the problem is in the ajax . . . .

Help would be much appreciated :rolleyes:

  • 写回答

2条回答 默认 最新

  • weixin_33724659 2014-03-12 12:22
    关注
    1. I don't know about this plugin and how it saves what checkboxes are checked, but you can look into that and then send that information to your controller.
    2. Alternatively you can save which models should be deleted in a session. On a checkbox click() (check if the check box is checked or unchecked) event call your controller with ajax to save the model's id in your session. then when the user clicks delete you can retrieve this data from the session.
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题