Skip to content

Commit

Permalink
Update chapter-14.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
nicozanf authored Jul 7, 2024
1 parent 901cc59 commit f7b4310
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docs/chapter-14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,39 @@ combine fields to be displayed together as the filter_out method would
You need to determine which method is best for your use case
understanding the different grids in the same application may need to
behave differently.


Grids with checkboxes
---------------------

While the grid, per se, does not support checkboxes, you can use custom columns to add one or more columns of checboxes.
You can also add the helpers logic (the grid uses helpers to generate HTML) to wrap it in a ``<form>`` and add one
or more submit bottons. You can then add logic to process the selected rows when the button is selected. For example:

.. code:: python
column = Column("select", lambda row: INPUT(_type="checkbox",_name="selected_id",_value=row.id))
@action("manage")
@action("manage/<path:path>")
@action.uses("manage.html", db)
def manage(path=None):
grid = Grid(path, db.thing, columns=[column, db.thing.name])
# if we are displaying a "select" grid page (not a form)
if not grid.form:
grid = grid.render()
# if checkboxes selection was submitted
if request.method == "POST":
# do something with the selected ids
print("you selected", request.POST.get("selected_id"))
# inject a ``<form>`` and a ``submit`` button
grid.children[1:] = [FORM(
*grid.children[1:],
DIV(INPUT(_type="submit",_value="do it!")),
_method="POST",
_action=request.url)]
return locals()
Notice in the above example ``request.POST.get("selected_id")`` can be a single ID (if one selected) or a list of IDs (if more than one elsected).

0 comments on commit f7b4310

Please sign in to comment.