使用easyui实现列表的批量删除

来源:互联网 发布:矩阵的一致性检验公式 编辑:程序博客网 时间:2024/04/30 16:45

使用easyui实现列表的批量删除 首先要做的就是增加一个多选框

<table id="otGrid" nowrap="false" style="height: 330px;"><thead><tr><th data-options="checkbox:true"></th> //就是这个,多选框


在列表的配置选项中 增加一个 singleSelect:false, 把true改为false  意思就是可以多选

然后就是要在列表中接收值了,原来单个删除时接收一个值,现在要接收一个数组

代码:// 删除操作按钮事件

$("#delBtn").bind("click", function() {// 得到选中的行//var selRow = otGrid.datagrid("getSelected");//返回选中一行 这个是注释过的  就是取一个var selRow = otGrid.datagrid("getSelections");//返回选中多行if(selRow.length==0){alert("请至少选择一行数据!");return false;}var ids=[];for (var i = 0; i < selRow.length; i++) {                 //获取自定义table 的中的checkbox值               var id=selRow[i].OTRECORDID;   //OTRECORDID这个是你要在列表中取的单个id           ids.push(id); //然后把单个id循环放到ids的数组中                  }             if(confirm("确定要删除选中的超温记录吗?")){$.getJSON("${CTX_ROOT}/TOtrecordsController?method=removeTOtrecordsPOList",{"array[]":ids},  //这一处,传过去的值一定要是变量名[]  例如:array[] ,把ids这个数组传到后台function(data){alert(data.msg); //这个是后台返回过来的msg值,提醒  if(1 == data.code){// 删除成功,则需要在树中删除节点  // 检修任务grid 执行loadotGrid.datagrid("reload");  /重新加载} });}});


java处理代码 

// 获取页面提交的主键参数

String[] array = request.getParameterValues("array[]");List<TOtrecordsPO> list = new ArrayList<TOtrecordsPO>();for (int i = 0; i < array.length; i++) {TOtrecordsPO totrecords = new TOtrecordsPO();totrecords.setOtrecordid(Long.valueOf(array[i]));list.add(totrecords);}tOtrecordsService.deleteAllTOtrecordsPO(list); //这个是我删除的方法 然后在我写的那个deleteAllTOtrecordsPO(list)方法里for (TOtrecordsPO to : entities) {this.deleteEntity(to);}



我循环调用单个删除

这样就好了


这是我的代码


请高手不要见笑

3 0