SQLForm.grid : is it possible to delete multiple rows at once ?

990 views
Skip to first unread message

sebsto

unread,
Mar 23, 2012, 7:02:55 AM3/23/12
to web...@googlegroups.com
Hello,

Is it possible to select and delete multiple rows with one button click using SQLFORM.grid ?  (instead of clicking delete on each row)
I tried the "selectable" property but this doesn't help to delete.
I searched the archive of this group / mailing-list without success

Thanks for your help

Seb

Anthony

unread,
Mar 23, 2012, 10:33:42 AM3/23/12
to web...@googlegroups.com
Is it possible to select and delete multiple rows with one button click using SQLFORM.grid ?  (instead of clicking delete on each row)
I tried the "selectable" property but this doesn't help to delete.
I searched the archive of this group / mailing-list without success

Not out of the box. I suppose you could add a column (via the "links" argument) with "delete" checkboxes, and then add a "delete checked" button to the page with a Javascript event handler that identifies the checked records, submits a request to the server, and then possibly reloads the whole page or just the grid via Ajax.

Anthony 

Derek

unread,
Mar 23, 2012, 8:46:59 PM3/23/12
to web...@googlegroups.com
Or you could avoid javascript, store the IDs of the "deleted" items in the session and do your own calls to the DAL to delete items.

Javier Pepe

unread,
Mar 24, 2012, 12:26:52 AM3/24/12
to web...@googlegroups.com
sabsto

You can use selectable, for example:

selectable = lambda ids: delete(ids)
form=SQLFORM.grid(query,selectable=selectable)

def delete(ids):
    to_delete=db(db.tabla.id.belongs(ids))
    to_delete.delete()

Anthony

unread,
Mar 24, 2012, 8:15:53 AM3/24/12
to web...@googlegroups.com
You can use selectable, for example:

selectable = lambda ids: delete(ids)
form=SQLFORM.grid(query,​selectable=selectable)

def delete(ids):
    to_delete=db(db.tabla.id.​belongs(ids))
    to_delete.delete()

Nice. Forgot about that. 

Sebastien Stormacq

unread,
Mar 26, 2012, 3:06:51 AM3/26/12
to web...@googlegroups.com
Thanks !

Sanjeet Kumar

unread,
Mar 26, 2012, 7:08:57 AM3/26/12
to web2py-users
can use the following :-

form=SQLFORM.grid(db.auth_user, create=False, selectable = lambda ids:
del_emp(ids))

def del_emp(ids):
if not ids:
response.flash='Please Select the Check-box to Delete'
else:
for row in ids:
db(db.auth_user.id == row).delete()
pass
pass
return ''

you can see the submit button at the bottom of grid you can select the
multiple check-box at a time and click the submit button it will
delete the all select-able row at a time


On Mar 26, 12:06 pm, Sebastien Stormacq <sebastien.storm...@gmail.com>
wrote:
> Thanks !
>
>
>
>
>
>
>
> On Saturday, March 24, 2012 5:26:52 AM UTC+1, Javier wrote:
>
> > sabsto
>
> > You can use selectable, for example:
>
> > selectable = lambda ids: delete(ids)
> > form=SQLFORM.grid(query,​selectable=selectable)
>
> > def delete(ids):
> >     to_delete=db(db.tabla.id.​belongs(ids))
> >     to_delete.delete()
>

Mandar Vaze

unread,
Sep 10, 2012, 9:29:51 AM9/10/12
to web...@googlegroups.com, sanje...@gmail.com


On Monday, March 26, 2012 4:38:57 PM UTC+5:30, Sanjeet Kumar wrote:
can use the following :-

form=SQLFORM.grid(db.auth_user, create=False, selectable = lambda ids:
del_emp(ids))

def del_emp(ids):
        if not ids:
                response.flash='Please Select the Check-box to Delete'
        else:
                for row in ids:
                        db(db.auth_user.id == row).delete()
                pass
        pass
        return ''


response.flash does not seem to work. But session.flash works.
So I assume the form is indeed submitted.

Is there a "web2py" way (I mean without java script) to prevent form submission if no records are selected ? 

-Mandar

Reply all
Reply to author
Forward
0 new messages