Jose,
sorry for the delay but I just came home a few hours ago actually 23h
but here is your long answer ;)
--> just add this line in your search() method returned dict:
actions = {'select': {'function': 'cell_clicked', 'params': []}}
and a click on a row will call cell_clicked with the cell_id as first param...
And now for the short answer:
you are responsible to provide the cell_clicked() javascript function
via the javascript attribute of your widget à la:
-------------------------------------------------------
import pkg_resources
import os
from turbogears.widgets.base import register_static_directory
# 'joseproject' should be replace by the name of your project module
pkg_path = pkg_resources.resource_filename('joseproject',
os.path.join("static", "javascript"))
register_static_directory("cellaction.javascript", pkg_path)
jscell_action = JSLink('cellaction.javascript', 'cellaction.js')
grid.javascript.append(jscell_action)
-------------------------------------------------------
then write your cellaction.js file in the
"joseproject/static/javascript" directory and all will be loaded :)
and now for the full blown example inspired by yours :
--------------
#!/usr/bin/env python
'''
example project for jose
'''
__author__ = 'Florent Aide, <[EMAIL PROTECTED]>'
__revision__ = 0
from turbogears import controllers, expose
from turbogears.widgets import AjaxGrid, JSLink
from turbogears.widgets.base import register_static_directory
import random
import os
import pkg_resources
pkg_path = pkg_resources.resource_filename('jose',
os.path.join("static", "javascript"))
register_static_directory("cellaction.javascript", pkg_path)
grid = AjaxGrid(refresh_url="search")
jscell_action = JSLink('cellaction.javascript', 'cellaction.js')
grid.javascript.append(jscell_action)
class Root(controllers.RootController):
'''my root controller'''
@expose(template="kid:jose.templates.mytest")
def index(self):
return dict(acfield=grid)
@expose(format="json")
def search(self):
'''method called by the Ajax grid'''
r = random.random() * 2
return dict(
headers = ["Hour", "Minute", "Second"],
rows = [
[r+1, r+2, r+3],
[r+11, r+12, r+13],
[r+21, r+22, r+23],
],
actions = {'select': {'function': 'cell_clicked', 'params': []}}
)
# vim: nocompatible expandtab tabstop=4 shiftwidth=4:
-------------------------------------------------
don't forget to define cell_clicked() inside your cellaction.js file
Hope this helps. And please give us feed-back on your success :)
Florent Aide
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---