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.
1 Answers
grid = SQLFORM.grid(..., selectable=lambda ids: [do something with record ids])
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')])
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.

- 25,466
- 3
- 28
- 57
-
Trying the "Action 1", "Action 2" approach from above (with some function calls replacing, "[do ... ids]") returns the message, "list object is not callable". Any ideas as to what could be happening? – Lamps1829 Aug 05 '13 at 21:11
-
Sorry, forgot that the second form of `selectable` shown above is only available in trunk. I believe the next stable release (which will include that feature) should be out very soon. – Anthony Aug 06 '13 at 02:27
-
Trying an alternative way to do this. Guess it warrants a new thread. – Lamps1829 Aug 06 '13 at 12:35
-
You might also consider switching to trunk. – Anthony Aug 06 '13 at 13:13
-
I'm in a more or less production environment with my current task, so to play it safe, rather than use the latest development version, I use the version to which web2py automatically upgrades (2.5.1-stable at the moment). – Lamps1829 Aug 06 '13 at 13:46
-
Using the same code, I got this error: TypeError: __call__() takes 1 positional argument but 2 were given. This is after switching to python3.6 – lobjc Mar 19 '19 at 07:39