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.person.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, user_signature=False, 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

On Tuesday, October 25, 2016 at 2:35:00 AM UTC-4, Madhavi wrote:
>
> Hi,
>
> I am new to web2py and am working on application with a SQLFORM grid with 
> the search feature along with selectable option. I added extra buttons to 
> my grid to set a boolean value for selected records using selectable 
> feature, and added another button to set a boolean value for all the 
> records in the table. Now, I also want to add a button the set this value 
> for only filtered records using the search feature. Is there a way using 
> which I can refer to the ids of only those records which are filtered 
> through the search widget to perform this manipulation only on those 
> records? To explain better, I have the below buttons in place:
>
> 1. Set true for all selected records
> 2. Set true for all records
>
> I also want to add an option to:
>
> 3. Set true for filtered records (filtered records refer to the ones 
> displayed on performing the search in the grid).
>
> Please let me know if this is possible,
>
> Thanks a ton,
>
> Madhavi
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to