Displaying SQL result sets

0 views
Skip to first unread message

dbdweeb

unread,
Nov 29, 2005, 4:55:47 PM11/29/05
to MochiKit
I'd like to display a result set from an SQL query into an HTML table
(or SELECT input) via AJAX with JSON (or XML). I looked at the
"Sortable AJAX table" demo but can't figure out how to use the
initWithData function to popluate the data. Python SQL results are
usually a list of lists, list of tuples, or a tuple of tuples. (I'm
using cx_Oracle so it's a list of tuples.) Can someone supply me with
some sample code to get started?

AtDhVaAnNkCsE !!!

Bob Ippolito

unread,
Nov 29, 2005, 5:15:24 PM11/29/05
to dbdweeb, MochiKit
Make the data look like domains.json or domains.xml, and then just
change the code that tells it which URL to use.

-bob

vida

unread,
Nov 30, 2005, 1:33:44 PM11/30/05
to MochiKit
on the MochiKit side (as pretty much described on the screencast):
function requestData(url) {
d=loadJSONDoc(url)
d.addCallback(showData)
}

function showData(result) {
html_table=TABLE(
,THEAD(null,row_display(result["headers"]))
,TBODY(null,map(row_display,result["data"]))
)
replaceChildNodes("div-id",html_table)
}

function row_display(row) {
return TR(null,map(partial(TD,null),row))
}

On the python side, return a
dict(headers=database.cursor.description,
data=database.cursor.fetchall())

Then do requestData(exposed-python-function-name)
Then profit.

-Facus.

Reply all
Reply to author
Forward
0 new messages