I use YUI for my web development. YUI can do lots of cool things with
your data if you feed it a JSON array of objects. I don't know about
other JS libraries, but I can say that accessing your data in JS in
this form is much faster and easier (with more readable code) than the
solution provided in this discussion:
http://groups.google.com/group/web2py/browse_thread/thread/cd6239716cf1d989/21e557c08f9113fd?lnk=gst&q=sqlrows+json#21e557c08f9113fd
I propose the following added method to the SQLRows object in order to
provide what I've described above:
---------------------
import gluon.contrib.simplejson as sj
...
def json(self, columnHeaders=True):
"""
serializes the table to a JSON list of objects
"""
cols=range(len(self.colnames))
colnames = self.colnames
resp = self.response
rows = range(len(self))
# Looping through a potentially large list, demands that we
precompute
# as much as we can to slim down the loop.
if columnHeaders:
lst=[dict([(colnames[j], resp[i][j]) for j in cols]) for i in
rows]
else:
lst=[[resp[i][j] for j in cols] for i in rows]
return sj.dumps(lst)
---------------------------
Note that setting the columnHeaders option to False will provide the
output as a list of lists per the discussion at:
http://groups.google.com/group/web2py/browse_thread/thread/cd6239716cf1d989/21e557c08f9113fd?lnk=gst&q=sqlrows+json#21e557c08f9113fd
I think this patch is Pythonic and web2pyic. Who's with me?