Commits

Anonymous committed fd954d1

Fixup DataTable sample

Comments (0)

Files changed (2)

tw2/yui/samples.py

 class DemoDataTable(twy.DataTable):
     id = twy.Column()
     name = twy.Column()
-    class datasrc(twy.LocalDataSource):
-        resources = twy.DataSource.resources + [
-            twc.JSLink(modname=__name__, filename="static/sample-data.js"),
-        ]
-        data = 'YAHOO.example.Data.accounts'
+    value = [{'id':1, 'name':'Joe'}, {'id':2, 'name':'Paul'}]

tw2/yui/widgets.py

     resources = [ # don't use YuiWidget.resources
         twc.JSLink(modname=__name__, filename="static/"+yui_version+"/datasource/datasource-min.js"),
     ]
-    responseSchema = twc.Param('TBD', default={'resultsList':'result'})
 
     def prepare(self):
         self.safe_modify('options')
         twc.JSLink(modname=__name__, filename="static/"+yui_version+"/connection/connection-min.js"),
     ]
     template = "genshi:tw2.yui.templates.xhrdatasource"
+    responseSchema = twc.Param('responseSchema', default={'resultsList':'result'})
     options = {
         'responseType': 3, # YAHOO.util.XHRDataSource.TYPE_JSON
     }
 
 class LocalDataSource(DataSource):
     template = "genshi:tw2.yui.templates.localdatasource"
-    #data = twc.Param('Name of the JavaScript array to use as the data source')
+    data = twc.Param('Name of the JavaScript array to use as the data source')
 
     def prepare(self):
         super(LocalDataSource, self).prepare()
         twc.JSLink(modname=__name__, filename="static/"+yui_version+"/button/button-min.js"),
     ]
     template = "genshi:tw2.yui.templates.datatable"
+    children = twc.Param('Columns for the table. These must be tw2.yui.Column widgets.')
     columns = twc.Variable()
 
     def prepare(self):
 
 
 class Column(twc.Widget):
-    """A column in a DataTable."""
-    options = twc.Param('Configuration options for the widget. See the YUI docs for available options.', 
-        default={'sortable':True, 'resizeable':True})
-    sortable = twc.Param(default=True)
-    resizeable = twc.Param(default=True)
-    label = twc.Param(default=twc.Auto)
-    key = twc.Param(default=None)
+    """A column in a DataTable. The TW id becomes the YUI key, and the TW key becomes the YUI field."""
+    options = twc.Param('Configuration options for the widget. See the YUI docs for available options.', default={})
+    sortable = twc.Param('Is the column sortable?', default=True)
+    resizeable = twc.Param('Is the column resizeable?', default=True)
+    label = twc.Param('Label for the field. Auto generates this from the id', default=twc.Auto)
+    formatter = twc.Param('Formatter function. Use a string like "currency" for a YUI built-in, or JSSymbol for a custom function.', default=None)
 
     def prepare(self):
         super(Column, self).prepare()
         if self.label is twc.Auto:
             self.label = twc.util.name2label(self.id) 
         self.options['label'] = self.label
-        if not self.key:
-            self.key = self.id
-        self.options['key'] = self.key
+        self.options['key'] = self.id
+        self.options['field'] = self.key
+        if self.formatter:
+            self.options['formatter'] = self.formatter
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.