Anonymous avatar Anonymous committed b6b14a3

Add DataTable widget

Comments (0)

Files changed (3)

tw2/yui/__init__.py

 from widgets import (Slider, TabView, AutoComplete, ColorPicker, Calendar,
-        Editor, TreeView, XHRDataSource, LocalDataSource, LogReader)
+        Editor, TreeView, XHRDataSource, LocalDataSource, LogReader, DataTable,
+        Column)

tw2/yui/samples.py

         ]
         data = 'YAHOO.example.Data.arrayStates'
         responseSchema = {'fields': ["state"]};
+
+
+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'

tw2/yui/widgets.py

         twc.JSLink(modname=__name__, filename="static/"+yui_version+"/logger/logger-min.js"),
     ]
     template = "genshi:tw2.yui.templates.logreader"
+
+
+class DataTable(YuiWidget, twc.CompoundWidget):
+    resources = YuiWidget.resources + [
+        twc.CSSLink(modname=__name__, filename="static/"+yui_version+"/datatable/assets/skins/sam/datatable.css"),
+        twc.CSSLink(modname=__name__, filename="static/"+yui_version+"/button/assets/skins/sam/button.css"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/dom/dom-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/event/element-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/dragdrop/dragdrop-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/element/element-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/datasource/datasource-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/event-delegate/event-delegate-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/datatable/datatable-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/button/button-min.js"),
+        twc.JSLink(modname=__name__, filename="static/"+yui_version+"/connection/connection-min.js"),
+    ]
+    template = "genshi:tw2.yui.templates.datatable"
+    datasrc = twc.Param('DataSource to use')
+    columns = twc.Variable()
+
+    @classmethod
+    def post_define(cls):
+        if hasattr(cls, 'datasrc'):
+            cls.datasrc = cls.datasrc(parent=cls, id='datasrc')
+
+    def __init__(self, **kw):
+        super(DataTable, self).__init__(**kw)
+        self.datasrc = self.datasrc.req()
+
+    def prepare(self):
+        super(DataTable, self).prepare()
+        self.datasrc.prepare()
+        self.columns = encoder.encode([c.options for c in self.c])
+
+
+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})
+    def prepare(self):
+        super(Column, self).prepare()
+        self.safe_modify('options')
+        self.options['key'] = self.id
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.