easyui实现多行删除

此文为博主原创内容,转载请说明出处,欢迎各位批评指点。
最近楼主在自己研究easyui数据网格多行删除操作,以下为本人经验总结,供大家参阅:
多行删除的思想就是:取到所选中多行的ID进行字符串拼接,传到后台对字符串分割,循环进行删除每一行。
所以说此问题的重点就是解决字符串的分割、拼接。

表格

	<div id="dlg" class="easyui-dialog"
		style="width: 500px; height: 300px;" title="编辑用户" iconCls="icon-edit"
		closed="true" closable="true">
		<s:form id="userForm" action="save" namespace="/testuser">
			<s:token />
			<s:hidden name="newUser.fuserid" id="newUser_fuserid"/>
			<table id="userTable" cellpadding=0 cellspacing=0 border=0
				class="ListTable" align="center" style="width: 40%">
				<tr>
					<td class="EditHead" nowrap><font color=red>*</font>&nbsp;用户账号</td>
					<td class="editTd"><input class ="noborder
							easyui-validatebox" data-options="required:true,validType:'length[1,50]'"
							type="text" name="newUser.floginname" id='newUser_floginname'
							maxlength="255" title="用户账号" /></td>
				</tr>
				<tr>
					<td class="EditHead" nowrap><font color=red>*</font>&nbsp;用户名称</td>
					<td class="editTd"><input class="noborder easyui-validatebox"
						data-options="required:true,validType:'length[1,50]'" type="text"
						name="newUser.fname" id='newUser_fname' maxlength="255"
						title="用户名称" /></td>
				</tr>
			</table>
		</s:form>
	</div>

js方法:

<script type="text/javascript">

$(document).ready(function(){
	var editIndex = undefined;
	$('#userTable').datagrid({
		url:'${contextPath}/testuser/queryUser.action?querySource=123',
		rownumbers:true,
		pagination:true,
		fitColumns:true,
		fit:true,
		idField:'fuserid',
		singleSelect:false,   //此处不能忘记改为false,否则不能多选
		striped:true,
		pageSize:10,
		toolbar:[{
			id:'delUser',
			text:'删除',
			iconCls:'icon-remove',
			handler:function(){
				var selectRows = $('#userTable').datagrid('getChecked');
				if(selectRows.length == 0){
					showMessage1('请选择要删除的用户!');
					return;
				}
				var fuserids = [];
				for (var i = 0; i < selectRows.length; i++) {
					fuserids += selectRows[i].fuserid + ",";    //把fuserid(字符串类型)以“,”拼接
	            }
				fuserids = fuserids.substr(0, fuserids.length - 1);   //去掉最后一个“,”
				//alert(fuserids);
				if (confirm('确定删除吗?')) {
				window.location.href="${contextPath}/testuser/delUser.action?fuserids="+fuserids;
					return true;
				} else {
					return false;
				}
			}
		}
	
	]
		columns:[[
				  {field:'fuserid',checkbox:true},
		          {field:'floginname',title:'用户账号',sortable:true, width:100},
		          {field:'fname',title:'用户姓名', width:100,
		        	editor:{type:'validatebox',options:{required:true}}  
		          },
		          {field:'fdepname',title:'所在单位', width:100},
		          {field:'fsex',title:'性别', width:100},
		]]
	});
});
</script>

后台代码:

public String delete() {
		String fuserids = this.getRequestParameter("fuserids");  //接受拼接后的字符串(id)
		//System.out.println(fuserids);
		String[] delFuserids = fuserids.split(",");   //分割字符串
		for (int i = 0; i < delFuserids.length; i++) {   //每次循环删除一行
			newUser = (UUser) this.testUserService.get(UUser.class,delFuserids[i]);
			if (newUser != null) {
				testUserService.delete(newUser);
			}
		}
		return SUCCESS;
	}
	```


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值