Overriding Grid/Smartgrid's 'Edit/Delete/View'

1,512 views
Skip to first unread message

Johann Spies

unread,
Oct 6, 2011, 7:48:20 AM10/6/11
to web...@googlegroups.com
How do I override the views/controllers  triggered by the buttons  mentioned in the subject line when using SQLFORM.grid/smartgrid?

Regards
Johann

--
 May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord!  His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence.
                                                    2 Pet. 1:2b,3a

apple

unread,
Oct 6, 2011, 8:36:26 AM10/6/11
to web2py-users
You can add your own buttons using:

links = [lambda row: A('Edit',_href=URL("controller","edit",
args=["update", tablename, a.id]))

and set editable, deletable, details to False.

Johann Spies

unread,
Oct 6, 2011, 8:47:09 AM10/6/11
to web...@googlegroups.com
On 6 October 2011 14:36, apple <sim...@gmail.com> wrote:
You can add your own buttons using:

links = [lambda row: A('Edit',_href=URL("controller","edit",
args=["update", tablename, a.id]))

and set editable, deletable, details  to False.



Thanks!

Johann

Javier Pepe

unread,
Oct 6, 2011, 8:42:20 AM10/6/11
to web...@googlegroups.com
Hello

Along with the question of Johann, you can add new buttons to the grid
/ SmartGrid, because the links are render as links, and not as
buttons.

Thanks

apple

unread,
Oct 6, 2011, 12:54:39 PM10/6/11
to web2py-users
If you use jqueryui then the links are rendered as buttons.

Adi

unread,
Dec 20, 2011, 8:08:57 PM12/20/11
to web...@googlegroups.com
is it possible to remove some of the related tables' buttons? 

Jim Steil

unread,
Dec 20, 2011, 8:57:25 PM12/20/11
to web...@googlegroups.com
Yes, you can pass a list of the tables you want to display through the linked_tables parameter.

grid = SQLFORM.smartgrid(db.customer, linked_tables=['note', 'order'])

Then it will only include buttons for the tables you've listed.

    -Jim


On 12/20/2011 7:08 PM, Adi wrote:
is it possible to remove some of the related tables' buttons? 

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.1890 / Virus Database: 2109/4693 - Release Date: 12/20/11


Cliff

unread,
Dec 20, 2011, 10:14:14 PM12/20/11
to web2py-users
You can learn more here:

http://web2py.com/books/default/chapter/29/7#SQLFORM.grid-and-SQLFORM.smartgrid-(experimental)

On Dec 20, 8:57 pm, Jim Steil <j...@qlf.com> wrote:
> Yes, you can pass a list of the tables you want to display through the
> linked_tables parameter.
>
> grid = SQLFORM.smartgrid(db.customer, linked_tables=['note', 'order'])
>
> Then it will only include buttons for the tables you've listed.
>
>      -Jim
>
> On 12/20/2011 7:08 PM, Adi wrote:
>
>
>
>
>
>
>
> > is it possible to remove some of the related tables' buttons?
>
> > No virus found in this message.
> > Checked by AVG -www.avg.com<http://www.avg.com>

Adnan Smajlovic

unread,
Dec 21, 2011, 11:16:19 AM12/21/11
to web...@googlegroups.com
Great. works perfect! Thanks a lot.
--

Thanks,
Adnan

video: http://vimeo.com/24653283


horridohobbyist

unread,
Jan 20, 2014, 11:44:12 PM1/20/14
to web...@googlegroups.com
I can't get this to work. I'm new to web2py. Perhaps I don't understand the argument-passing mechanism...

In SQLFORM.grid, I have:

links=[lambda row: A('View',_href=URL('view',args=[db.products,row.id]))],

In the default controller, I have:

def view(table,id):
    return dict()

I get the following error:

invalid function (default/view)


...with this:


Shouldn't the arguments 'products' and '11' be passed to the view function? What am I not understanding?

Thanks.

Johann Spies

unread,
Jan 21, 2014, 1:35:52 AM1/21/14
to web...@googlegroups.com
Did you create a function 'view'  in the default controller?

Regards
Johann


--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

horridohobbyist

unread,
Jan 21, 2014, 8:00:19 AM1/21/14
to web...@googlegroups.com
Yes, I did. But I shouldn't have included arguments in the 'view' function. That was the error.

So how do I extract the arguments 'products' and '11' (in my example) in the view function? response._vars apparently does not contain them.

Thanks.

horridohobbyist

unread,
Jan 21, 2014, 8:15:15 AM1/21/14
to web...@googlegroups.com
Ah, I think I know! The arguments are passed in request.args. Right?

Anthony

unread,
Jan 21, 2014, 9:25:11 AM1/21/14
to web...@googlegroups.com
links=[lambda row: A('View',_href=URL('view',args=[db.products,row.id]))],

First, note that the URL function produces a string, so putting db.products in args is equivalent to str(db.products), which will result in just "products".
 
def view(table,id):
    return dict()

As noted in the book, any function in a controller that accepts arguments is not exposed as an action accessible via URL (in other words, it is a private function). To access args passed via a URL (i.e., the part of the URL path that comes after /app/controller/function), you must use request.args (i.e., request.args(0) is the first argument, etc.).

Anthony
Reply all
Reply to author
Forward
0 new messages