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 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题