Where/How I can personalize the CRUD behavior and Layout ?

40 views
Skip to first unread message

Leandro - ProfessionalIT

unread,
Jul 22, 2009, 3:10:08 PM7/22/09
to web2py-users
Hi,

I'm sorry by my stupid questions and by terrible english , but...
I want to personalize the behavior and the Layout of CRUD
funcionality, about this, I have Three questions:

1) In the action default/data/select/"table_name" the generated
output is a HTML table with all records and columns of the
"table_name". Well, if I want hide some columns and implement a
pagination in the records..Where/How I can do this ?

2) How to implement a filter/search in the records in this
action ../select/"table_name" ? for example, I developed an
application [1] in Django (and I want migrate this application to
Web2Py ) where I implemented this behavior, which filters the records
of the table (and implement a pagination also).

3) How to personalize the generated HTML by the CRUD, for example,
can I assign an ID or a CSS class for the generated HTML table of
select action ?

Thank's !
Leandro Severino.

[1] - http://www.pampacomercial.com.br/sistema/cadastros/grupo-produto/

Fran

unread,
Jul 22, 2009, 4:55:17 PM7/22/09
to web2py-users
On Jul 22, 8:10 pm, Leandro - ProfessionalIT <lsever...@gmail.com>
wrote:
>    1) In the action default/data/select/"table_name" the generated
> output is a HTML table with all records and columns of the
> "table_name". Well, if I want hide some columns

db.table.field.readable = False

> and implement a pagination in the records..Where/How I can do this ?

I do paginationclient-side using the excellent jQuery dataTables
plugin:
http://datatables.net

Previously I did it server-side based on this article:
http://99babysteps.appspot.com/how2/default/article_read/2
There are simpler examples around too (search this group for
'pagination')

>    2) How to implement a filter/search in the records in this
> action ../select/"table_name" ? for example, I developed an
> application [1] in Django (and I want migrate this application to
> Web2Py ) where I implemented this behavior, which filters the records
> of the table (and implement a pagination also).

Again, I use dataTables for this.
Previously I used an autoComplete plugin to do Search.

>    3) How to personalize the generated HTML by the CRUD, for example,
> can I assign an ID or a CSS class for the generated HTML table of
> select action ?

Unfortunately crud doesn't support doing things like:
form = crud.create(db.table, _id='myid', _class='myclass')

You need to drop down a layer to use SQLFORM for this:
form = SQLFORM(db.table, _id='myid', _class='myclass')

F

Fran

unread,
Jul 22, 2009, 5:01:42 PM7/22/09
to web2py-users
On Jul 22, 9:55 pm, Fran <francisb...@googlemail.com> wrote:
> >    3) How to personalize the generated HTML by the CRUD, for example,
> > can I assign an ID or a CSS class for the generated HTML table of
> > select action ?
> Unfortunately crud doesn't support doing things like:
> form = crud.create(db.table, _id='myid', _class='myclass')
> You need to drop down a layer to use SQLFORM for this:
> form = SQLFORM(db.table, _id='myid', _class='myclass')

The other thing you can do is to define in the controller, as-usual:
form = crud.create(db.table)

But then use a custom form in the View:
{{=form.custom.begin}}
{{=form.custom.label.group_id}}
{{=form.custom.widget.group_id}}
{{=form.custom.comment.group_id}}
{{=form.custom.submit}}
{{=form.custom.end}}

& wrap your own custom HTML (with whatever IDs, classes you like)
around that.

NB The default IDs are already very CSS-friendly, so you should be
able to make use of those & not need to define your own.

Going back to the original question I see you were looking at the
output of crud.select() which *does* support the custom attributes I
highlighted earlier, so this works:
crud.select(db.table, _id='myid', _class='myclass')

F

ProfessionalIT

unread,
Jul 22, 2009, 6:30:20 PM7/22/09
to web2py-users
Fran,

> >    1) In the action default/data/select/"table_name" the generated
> > output is a HTML table with all records and columns of the
> > "table_name". Well, if I want hide some columns
>
> db.table.field.readable = False
This resolve the problem.
>
> > and implement a pagination in the records..Where/How I can do this ?
>
> I do paginationclient-side using the excellent jQuery dataTables
> plugin:http://datatables.net

Humm, How to integrate this datatables with Web2Py ? Do you have a
example ?

> Previously I did it server-side based on this article:http://99babysteps.appspot.com/how2/default/article_read/2
> There are simpler examples around too (search this group for
> 'pagination')
This code have sintax error and don't work.

> >    2) How to implement a filter/search in the records in this
> > action ../select/"table_name" ? for example, I developed an
> > application [1] in Django (and I want migrate this application to
> > Web2Py ) where I implemented this behavior, which filters the records
> > of the table (and implement a pagination also).
>
> Again, I use dataTables for this.
> Previously I used an autoComplete plugin to do Search.

Where Can Find this ?

Another idea... Do you have a Simple Demo App that solve my
problem ? If you have..Do you can send me by mail ?

Thank's
Leandro.

ProfessionalIT

unread,
Jul 22, 2009, 6:31:34 PM7/22/09
to web2py-users


> NB The default IDs are already very CSS-friendly, so you should be
> able to make use of those & not need to define your own.
>
> Going back to the original question I see you were looking at the
> output of crud.select() which *does* support the custom attributes I
> highlighted earlier, so this works:
> crud.select(db.table, _id='myid', _class='myclass')
>

Very good !, this resolve my problem.

Thank's
Leandro.

Fran

unread,
Jul 22, 2009, 6:49:02 PM7/22/09
to web2py-users
On Jul 22, 9:55 pm, Fran <francisb...@googlemail.com> wrote:
> >    3) How to personalize the generated HTML by the CRUD, for example,
> > can I assign an ID or a CSS class for the generated HTML table of
> > select action ?
> Unfortunately crud doesn't support doing things like:
> form = crud.create(db.table, _id='myid', _class='myclass')

This works though :)
form = crud.create(db.table)
form['_class'] = 'myclass'
form['_id'] = 'myid'

F

Fran

unread,
Jul 22, 2009, 6:52:31 PM7/22/09
to web2py-users
On Jul 22, 11:30 pm, ProfessionalIT <lsever...@gmail.com> wrote:
> > > and implement a pagination in the records..Where/How I can do this ?
> > I do paginationclient-side using the excellent jQuery dataTables
> > plugin:http://datatables.net
>    Humm, How to integrate this datatables with Web2Py ? Do you have a
> example ?

Controller:
items = crud.select(table, _id='list')

Add this to your view:
<script src="/{{=request.application}}/static/scripts/
jquery.dataTables.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">//<![CDATA[
$(document).ready(function() {
$('#list').dataTable();
} );
//]]></script>
{{=items}}

F

ProfessionalIT

unread,
Jul 22, 2009, 6:54:32 PM7/22/09
to web2py-users
> This works though :)
> form = crud.create(db.table)
> form['_class'] = 'myclass'
> form['_id'] = 'myid'
>
Perfect, this works fine.

Fran

unread,
Jul 22, 2009, 6:55:08 PM7/22/09
to web2py-users
On Jul 22, 11:30 pm, ProfessionalIT <lsever...@gmail.com> wrote:
> > Previously I did it server-side based on this article:http://99babysteps.appspot.com/how2/default/article_read/2
> > There are simpler examples around too (search this group for
> > 'pagination')
>    This code have sintax error and don't work.

I modified it for my app, but it's customized around my app:
http://trac.sahanapy.org/browser/models/01_RESTlike_controller.py

> > >    2) How to implement a filter/search in the records in this
> > > action ../select/"table_name" ? for example, I developed an
> > > application [1] in Django (and I want migrate this application to
> > > Web2Py ) where I implemented this behavior, which filters the records
> > > of the table (and implement a pagination also).
> > Again, I use dataTables for this.
> > Previously I used an autoComplete plugin to do Search.
>    Where Can Find this ?

dataTables will work just as-above.

The old autocomplete Search is here:
http://trac.sahanapy.org/browser/views/_searchbox.html
Customized for my app, but gives you the idea...

>    Another idea... Do you have a Simple Demo App that solve my
> problem ? If you have..Do you can send me by mail ?

No ;)

You can browse around the full app, but it's not a simple example...

F

ProfessionalIT

unread,
Jul 22, 2009, 7:14:08 PM7/22/09
to web2py-users
Ok, Fran
Now, I have all information to resolve my problem and my questions !.

Thanks for the all respost.

Leandro.

Fran

unread,
Jul 23, 2009, 6:30:08 AM7/23/09
to web2py-users
2009/7/23 Alex Fanjul <alex....@gmail.com>:
> NameError: global name 'A' is not defined
> Do I have to import gluon in the module? how?
> My view code is like this:
> {{from helpers import pagenav as pagenav}}

I didn't write the helpers module & I don't use it in the same way
that post does.
(I define a variant thereof in my model rather than a module, although
the module would be more efficient since it shouldn't ever be called
now unless ppl have javascript disabled)

If modules call gluon functions, then yes, they need to be imported
within that module.
This should fix that error, although there may be other parts you need
to import as well:
from gluon.http import *

> Another question: could you give me an example to call shn_rest_controller??

Very simple ;)
http://trac.sahanapy.org/browser/controllers/cr.py
def shelter():
return shn_rest_controller(module, 'shelter')

F
Reply all
Reply to author
Forward
0 new messages