Sort multiple tables

54 views
Skip to first unread message

pbt

unread,
Jul 2, 2016, 7:36:17 AM7/2/16
to web2py-users
I am new to web2py .Thanks in advance. Please help me doing this. I have multiple tables with one record in each table as shown in the screenshot.I want to sort the tables using different parameters of the table. I want to keep a drop-down to sort records according to rent,size,location,etc...
Screenshot from 2016-07-02 16:51:48.png

isi_jca

unread,
Jul 3, 2016, 4:26:53 PM7/3/16
to web2py-users
Hi!!!

Look at in attached file, maybe you can get some idea.

Regards.
web2py.app.Sorting.w2p

pbreit

unread,
Jul 3, 2016, 7:56:55 PM7/3/16
to web...@googlegroups.com
We might need to see some of your code, specifically your models.

Why do you have multiple tables?

I could see you having one table called "property" such as:

db.define_table('property',
 
Field('location'),
 
Field('size'),
 
Field('rent'))

And then in your controller:

def search():
 
if request.vars.orderby == 'size':
    orderby = db.property.size
 
elif request.vars.orderby == 'rent':
    orderby = db.property.rent
 
else:
   
orderby = db.property.location
  properties
= db(db.property.id>0).select(orderby=orderby)
 
return dict(properties=properties)

Then a URL:

Message has been deleted

pbt

unread,
Jul 3, 2016, 11:17:46 PM7/3/16
to web2py-users
@pbreit
In models,I have only 1 table.By multiple tables,I mean multiple tables in view.I found a jquery plugin for sorting data in a single table.That is why I wrote multiple tables so that no one will suggest jquery plugin for that.
Message has been deleted

pbt

unread,
Jul 4, 2016, 12:26:18 AM7/4/16
to web2py-users
@pbreit
I tried your code,it did not work.It works for sorting by location. 
In models
db.define_table('listspace',
  
Field('warehouse_location','string'),
  
Field('warehouse_totalsize','string'),
  
Field('contract_rent','string'))
In controller
def GetAllApprovedWarehouses():
print request.vars.sort
if request.vars.sort == 'size':
order = db.listspace.warehouse_totalsize
elif request.vars.sort == 'rent':
order = db.listspace.contract_rent
else:
order = db.listspace.warehouse_location
listSpaceRequests = db().select(db.listspace.ALL,orderby=order)
return dict(listSpaceRequests=listSpaceRequests)

pbt

unread,
Jul 4, 2016, 2:25:42 AM7/4/16
to web2py-users
@pbreit
I found the mistake. I wrote string instead of integer for rent and size. Thank you for helping.
Reply all
Reply to author
Forward
0 new messages