Note, the "searchable" argument can be a custom callable -- so, you can create a custom function that first calls the default internal query builder to get the query that filters the records, then run the update using that query, and then simply return the query for use by the grid. Here is an example:
def index():
grid_query = db.mytable.id > 0
selectable=[('Set Selected True', selected_true_callback),
('Set All True', all_true_callback)]
if 'keywords' in request.get_vars:
selectable.append(('Set Filtered True', lambda r: None))
def update_filtered(sfields, keywords):
search_query = SQLFORM.build_query(sfields, keywords)
if 'submit_2' in request.post_vars:
db(grid_query & search_query).update(myboolean=True)
return search_query
grid = SQLFORM.grid(grid_query, selectable=selectable,
searchable=update_filtered)
return dict(grid=grid)
In the above, "selectable" is a list of tuples defining two or three buttons corresponding to updating selected, all, or (optionally) filtered records. The grid will name each button "submit_0", "submit_1", and "submit_2", respectively. Whenever a search request comes in, the grid will call update_filtered (passing in the search fields and keywords). This function first simply calls the built-in query builder, just as the grid normally would, generating a DAL query for the search. The code determines if the "Set Filtered True" button was clicked by checking for "submit_2" in request.post_vars. In that case, it defines the filtered set of records by applying the main query for the grid in addition to the search query, and then updates that set of records (note, if your first argument to SQLFORM.grid is just a table rather than a query, you can skip the grid_query part of the code). Finally, it returns the search query for the grid to use as usual.
Note, in "selectable", the callback function for "Set Filtered True" is simply a do-nothing lambda function, as there won't actually be any selected records in this case -- we're just using "selectable" as a convenient way to add an additional submit button to the grid.
Anthony