将一列复选框添加到 SQLFORM.grid [英] Adding a column of checkboxes to an SQLFORM.grid

查看:32
本文介绍了将一列复选框添加到 SQLFORM.grid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个网格,其中第一列不包含标题,由复选框组成,最后几列是链接列(使用 'links' 参数生成),并生成中间列来自带有fields"参数的数据库字段.生成复选框列的最佳方法是什么?谢谢.

I'd like to have a grid in which the first column contains no header, and consists of checkboxes, the last couple of columns are columns of links (generated with the 'links' parameter), and the intermediate columns are generated from database fields with the 'fields' parameter. What's the best way to go about generating the column of checkboxes? Thank you.

推荐答案

grid = SQLFORM.grid(..., selectable=lambda ids: [do something with record ids])

这将在左侧添加一列复选框,并在网格底部添加一个提交"按钮.单击提交"按钮时,生成网格的操作将接收已检查记录的记录 ID 列表,这些 ID 将传递给selectable"参数(该参数应该是一个可调用的列表)记录 ID,如上).

That will add a column of checkboxes on the left and a "Submit" button at the bottom of the grid. When the "Submit" button is clicked, the action that generated the grid will receive a list of record IDs for the checked records, and those IDs will be passed to the "selectable" argument (which should be a callable that takes a list of record IDs, as above).

您可以控制提交按钮的标签,甚至可以通过将列表/元组列表作为可选"参数传递来添加附加功能以应用于已检查的记录:

You can control the label of the submit button and even add additional functions to apply to the checked records by passing a list of lists/tuples as the "selectable" argument:

grid = SQLFORM.grid(...,
    selectable=[('Action 1', lambda ids: [do action 1 with ids], 'class1'),
                ('Action 2', lambda ids: [do action 2 with ids], 'class2')])

在这种情况下,在网格底部,您会看到标记为操作 1"和操作 2"的按钮,并且将根据单击的按钮执行相应的操作.每个元组中的第三个元素是一个可选的 CSS 类,它将被添加到该操作的按钮元素中.

In that case, at the bottom of the grid you will get buttons labeled "Action 1" and "Action 2", and the appropriate action will be executed depending on which button is clicked. The third element in each tuple is an optional CSS class that will be added to the button element of that action.

这篇关于将一列复选框添加到 SQLFORM.grid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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