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

Changes between Version 1 and Version 2 of AjaxGrid


Ignore:
Timestamp:
04/20/06 04:16:15 (13 years ago)
Author:
fredlin
Comment:

init

Legend:

Unmodified
Added
Removed
Modified
  • AjaxGrid

    v1 v2  
    1 ''' 
    2 ---- 
     1= Ajax Grid Widget= 
     2 
     3This documentation is from Steve Bergman's post in [http://groups.google.com/group/turbogears/browse_thread/thread/fb6c3611b49af727/3d4d4ad72610b638#3d4d4ad72610b638 group] 
     4 
     5 
     6Using ajaxgrid is really quite simple.  For future first-timers like 
     7me, here is an easy example which works with TG 0.9a4: 
     8 
     9== 1. Quick start a project == 
     10 
     11 
     12== 2. Edit controllers.py == 
     13Edit controllers.py to look like the following: 
    314 
    415{{{ 
    5 [''fcvfd''] 
    6 }}}''' 
    7 ==  =='''' 
     16#!python 
     17import cherrypy 
     18import turbogears 
     19from turbogears import controllers, expose, redirect 
     20from turbogears import identity 
     21from turbogears.widgets import AjaxGrid 
     22from datetime import datetime 
     23 
     24grid = AjaxGrid(refresh_url="/search", defaults=dict(q='turbogears')) 
     25 
     26class Root(controllers.RootController): 
     27 
     28  @expose(template=".templates.form") 
     29  def index(self): 
     30      return dict(form=grid) 
     31 
     32  @expose(format="json") 
     33  def search(self, q): 
     34 
     35       # Fake a row of results 
     36       date = datetime.today() 
     37       hour = date.strftime('%H') 
     38       minute = date.strftime('%M') 
     39       second = date.strftime('%S') 
     40 
     41       return dict( 
     42           headers = ["Hour", "Minute", "Second"], 
     43           rows = [[hour, minute, second]], 
     44  ) 
     45}}} 
     46 
     47== 3. Create the template == 
     48Create the template "form.kid" and make it look like this:  
     49 
     50{{{ 
     51<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
     52<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#" 
     53    py:extends="'master.kid'"> 
     54<head> 
     55  <meta content="text/html; charset=UTF-8" http-equiv="content-type" 
     56py:replace="''"/> 
     57  <title>Ajaxgrid Example</title> 
     58</head> 
     59  <body> 
     60    <span py:content="form.display()"></span> 
     61  </body> 
     62</html> 
     63}}} 
     64 
     65== 4. Try it out == 
     66Start your project and try it out.  You should get a single row with 
     67the current hour, minute, and second.   
     68 
     69It should update when you click 'Update'.  
     70 
     71