Grails - 批量使用一列复选框更新表格行 [英] Grails - Bulk Update table rows using a column of checkboxes

查看:94
本文介绍了Grails - 批量使用一列复选框更新表格行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,其行可以在线修改。每行末尾都有一个提交按钮列。这很好,当我遍历域对象的后备列表时,将每个表单都放入一个表单中,并以这种方式单独提交。

I have a table whose rows can be modified in-line. There is a submit button column at the end of each row. This works fine, as I loop through the backing list of domain objects, put each in a form, and submit them individually that way.

当我添加一个复选框列允许用户批量更新多行。批量更新操作的按钮位于该表格之外,并且也是每行的格式。当我点击表外部的批量更新按钮时,如何获得所选行的支持域对象?

My problem arises when I add a column of checkboxes to allow the user to bulk update multiple rows. The button for the bulk update operation is outside that table, and also the forms of each row. How do I get the backing domain objects of the selected rows when I hit the Bulk Update button outside the table?

我知道我可以将一个字段添加到域对象特别是复选框,但我不想这样做,因为它看起来很乱,只是UI的一个后果,我不得不使用它来实现功能目的。

I realise I could probably add a field to the domain objects specifically for the checkbox but I don't want to have to do that as it seem messy and just a consequence of the UI I have to use instead of serving a functional purpose.

感谢您提供任何帮助,请告知我是否需要更多信息!

Thanks in advance for any help, let me know if you need more information!

Tony

Tony

推荐答案


  1. 不要为每行保留一个表单,将其保留为一个大表单。 给每个复选框使用相同的'名称,并在后端可以将其作为列表进行访问。
    示例:< g:checkbox name =selectedRow/>

  2. 同样为每个栏中的每个输入字段赋予相同的名称。例如,给所有行中输入年龄的文本框设置相同的名称。

  3. 现在在后端,所有列输入都可以作为常规列表访问。

  4. 通过执行'params.selectedRow'(selectedRow是给我们上面的复选框的名称)提取复选框输入

  5. 现在在该列表中找到具有值的复选框true,将此复选框列表的索引与其余输入相匹配,然后进行更新。

  1. Don't keep one form for each row, keep it as one big form.
  2. Give each checkbox the same 'name', and on the backend you can access it as a list.
    Example: <g:checkbox name="selectedRow" />
  3. Similarly give each input field in each column the same name also. For example, give all textboxes which take the input of age in all the rows the same name.
  4. Now on the backend all the column inputs can be accessed as groovy lists.
  5. Extract the checkbox inputs by doing 'params.selectedRow' (selectedRow was the name given to our checkboxes above)
  6. now in that list find the checkboxes which have value true, match the indexes of this checkbox list with the rest of the inputs, and update them.

我尝试过答案尽可能详细,让我知道你是否不明白任何部分。

I've tried to make this answer as detailed as possible, let me know if you didnt understand any part.

这篇关于Grails - 批量使用一列复选框更新表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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