wiki:AjaxGrid
Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Version 3 (modified by anonymous, 13 years ago) (diff)

--

Ajax Grid Widget

This documentation is from Steve Bergman's post in  group

Using ajaxgrid is really quite simple. For future first-timers like me, here is an easy example which works with TG 0.9a4:

1. Quick start a project

2. Edit controllers.py

Edit controllers.py to look like the following:

import cherrypy
import turbogears
from turbogears import controllers, expose, redirect
from turbogears import identity
from turbogears.widgets import AjaxGrid
from datetime import datetime

grid = AjaxGrid(refresh_url="/search")

class Root(controllers.RootController):

  @expose(template=".templates.form")
  def index(self):
      return dict(form=grid)

  @expose(format="json")
  def search(self):

       # Fake a row of results
       date = datetime.today()
       hour = date.strftime('%H')
       minute = date.strftime('%M')
       second = date.strftime('%S')

       return dict(
           headers = ["Hour", "Minute", "Second"],
           rows = [[hour, minute, second]],
  )

3. Create the template

Create the template "form.kid" and make it look like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
    py:extends="'master.kid'">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type"
py:replace="''"/>
  <title>Ajaxgrid Example</title>
</head>
  <body>
    <span py:content="form.display()"></span>
  </body>
</html>

4. Try it out

Start your project and try it out. You should get a single row with the current hour, minute, and second.

It should update when you click 'Update'.