将所选行从datatable发送到action方法? [英] Sending the selected rows from datatable to action method?

查看:127
本文介绍了将所选行从datatable发送到action方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用数据表在jsp页面显示客户记录,其中我显示了客户姓名,姓氏,部门,加入日期在数据表中。
我有一个列是选择框。现在用户可以从用户选择任何数量的客户记录,并在服务器端发送到操作更新。在我的
jquery函数中,我获取数据表中的所选行。
我期待的是将这些行从ajax发送到action方法,该方法有一个方法参数作为列表,但是我不能弄清楚如何将这些行发送到action方法? (表示所选行),我可以从UI中的表示所选行的列表中的每一行提取字段值。
但我不确定列表将包含什么类型的对象?有人可以用正确的方向指出一些简单的例子吗?

i am using data table to show the customer records on jsp page where i show customer name,last name,department,joining date in data table. i have one more column which is select box. now user can user select any number of customer records from ui and send to action on server side for update. In my jquery function i get the selected rows in data table. But i am not able to figure out how to send the these rows to action method? what i am expecting is i send these rows from ajax to action method which has one method parameter as list(representing the selected rows) and i can extract field values from each row in list representing selected rows from UI. But i am unsure what will be type of object that list will contain?Can someone point me in right direction with some brief example ?

推荐答案

为什么不在每行中给出一个复选框,其值将是相应记录的ID

Why dont you give a checkbox in each row whose value will be the id of the corresponding record

<input type="checkbox" name="rec" value="{id of the record}"/>

然后当您提交获取所选的ID

Then when you submit get the selected ids

var selectedRec="";
$("input[name='rec']:checked").each(function(){
  selectedRec += $(this).val()+","; 
});

您现在可以通过 selectedRec 作为字符串变量。在您的操作中,您可以将该字符串拆分为数组

you can now pass selectedRec to the action as a string variable. In your action you can split this string as array

String[] recArray =  selectedRec.split(",");

然后在循环中你可以得到每个id如下

Then in the loop you can get each id as follows

int customerId = Integer.parseInt(recArray[i]);

这篇关于将所选行从datatable发送到action方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆