web2py的SQLFORM.grid构造时,可以在links增加button构建行操作按钮:手册是这样写的:
links
is used to display new columns which can be links to other pages. The links
argument must be a list of dict(header='name', body=lambda row: A(...))
where header
is the header of the new column and body
is a function that takes a row and returns a value. In the example, the value is a A(...)
helper.
但是按钮太多占空间,按钮太多无法摆放:
要是编程下拉菜单多好,我们直接用web2py的XML直接输出html能力来构造,改成:
dict(header='name', body=lambda row: XML(...)) 格式,看示例
links=[dict(header='操作', body=lambda row: XML('<a class="nav-link dropdown-toggle" style="color:#007bff;font-weight:bold" data-toggle="dropdown">操作菜单</a> ' '<div class="dropdown-menu dropdown-menu-right">' '<a class="dropdown-item" href="/employee/edit/'+ str(row.id)+'">变更</a>' '<a class="dropdown-item" href="/employee/delete/'+ str(row.id) +'">删除</a>' '<a class="dropdown-item" target="_blank" href="/employee/view/' + str(row.id) +'">查看</a></div>' ))],
看看效果: