Problem doing a sortby in Smartgird

31 views
Skip to first unread message

Dan Kozlowski

unread,
Mar 7, 2014, 7:23:43 PM3/7/14
to web...@googlegroups.com
I have had this problem since last year and it never got resolved. I have a smartgird that I need to oder by date in dec order. The grid works fine until I select a child link. It the tells me query not supported. I hope some can help.




黄祥

unread,
Mar 7, 2014, 7:53:47 PM3/7/14
to web...@googlegroups.com
you must set it on the dict for each table.
e.g.
models/db.py
db.define_table('category', 
Field('name'), 
format = '%(name)s')

db.define_table('product', 
Field('name'), 
Field('category', 'reference category'), 
format = '%(name)s')

controllers/default.py
def category():
grid = SQLFORM.smartgrid(db.category, orderby = dict(category = ~db.category.name, product = db.product.name) )
return locals()

best regards,
stifan

Dan Kozlowski

unread,
Mar 7, 2014, 10:13:32 PM3/7/14
to web...@googlegroups.com
stifan,


I am still have trouble after following your example. All I want to do is db.dalily_counts.add_date ~ and db.history.add_date ~ . Any chance you can look at my code below and help ?

I appreciate it.





def dailycounts():
    grid=SQLFORM.smartgrid(db.daily_counts, orderby=None,
  user_signature=False,create=False,editable=False,deletable=False, paginate=10,  fields=[db.daily_counts.add_date,db.daily_counts.encrypt_count,db.daily_counts.decrypt_count,db.daily_counts.error_count,db.daily_counts.directory_create_count,db.daily_counts.client_add_count, db.history.client_id_dc, db.history.add_date, db.history.encryption_type,db.history.out_filename])
    return locals()
     



--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/cSJjVIVcPXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

黄祥

unread,
Mar 7, 2014, 10:27:21 PM3/7/14
to web...@googlegroups.com
please use dict() when you deal with smartgrid that reference to another table 
e.g. not tested 
def dailycounts():
fields = dict(daily_counts = [db.daily_counts.add_date, db.daily_counts.encrypt_count, 
 db.daily_counts.decrypt_count, db.daily_counts.error_count, 
 db.daily_counts.directory_create_count, db.daily_counts.client_add_count], 
 history = [db.history.client_id_dc, db.history.add_date, db.history.encryption_type, 
db.history.out_filename] )
orderby = dict(daily_counts = ~db.dalily_counts.add_date, history = ~db.history.add_date)
# similar to create = False, but you can make it flexible e.g. daily_counts = True, history = False
create = dict(daily_counts = False, history = False)
# similar to editable = False, but you can make it flexible e.g. daily_counts = True, history = False
editable = dict(daily_counts = False, history = False)
# similar to deletable = False, but you can make it flexible e.g. daily_counts = True, history = False
deletable = dict(daily_counts = False, history = False)
    grid = SQLFORM.smartgrid(db.daily_counts, user_signature = False, create = create, editable = editable, 
deletable = deletable, paginate = 10, orderby = orderby, fields = fields )

Dan Kozlowski

unread,
Mar 10, 2014, 1:37:18 PM3/10/14
to web...@googlegroups.com
Stifan,

Thanks for your help this solved the problem after 1 year.


On Fri, Mar 7, 2014 at 6:53 PM, 黄祥 <steve.van...@gmail.com> wrote:

--
Reply all
Reply to author
Forward
0 new messages