views:

44

answers:

1

I have a pylons web-page with a table. I have created python functions in the template which help with the construction of the table html. One of these functions takes an 'item' and generates an html row while also adding css zebra striping. The other def generates the header row's html.

This works perfectly for loading the initial table using the context variable 'items'. However, when I try to update the table via ajax, I pull new table contents off the server in json format. My 'items' are then javascript objects in a javascript array. I can no longer use the pylons 'getHeaderHtml()' and 'getRowHtml(item)'. So the handling of my zebra striping as well as the formatting of the html must be duplicated? There has to be a better way, right?

Thanks!

+1  A: 

One possibility would be to actually generate the AJAX HTML server-side (instead of generating JSON), and insert it right into the DOM tree (instead of parsing the JSON and generating the HTML on the client). Then you could use the same functions on the server side to generate the AJAX rows before they are shipped off. An advantage here is that you don't have to worry about parsing anything in the browser, so the JavaScript could become much simpler, and potentially faster.

Adam Batkin