[Checkins] SVN: grokui.introspector/trunk/src/grokui/introspector/util.py Add helper for generating YUI datatable init.

Uli Fouquet uli at gnufix.de
Fri May 1 18:48:45 EDT 2009


Log message for revision 99661:
  Add helper for generating YUI datatable init.

Changed:
  U   grokui.introspector/trunk/src/grokui/introspector/util.py

-=-
Modified: grokui.introspector/trunk/src/grokui/introspector/util.py
===================================================================
--- grokui.introspector/trunk/src/grokui/introspector/util.py	2009-05-01 19:22:41 UTC (rev 99660)
+++ grokui.introspector/trunk/src/grokui/introspector/util.py	2009-05-01 22:48:44 UTC (rev 99661)
@@ -83,3 +83,38 @@
     # Get rid of possible CVS id.
     lines = [line for line in lines if not line.startswith('$Id')]
     return render_text('\n'.join(lines), format=format)
+
+def datatable_init(tableid, containerid, columns):
+    """Initialize a YUI datatable
+    """
+    fielddefs = ",".join(['{key:"%s"}' % x['key'] for x in columns])
+    col_defs = []
+    for col in columns:
+        key = col['key']
+        label = key
+        if 'label' in col.keys():
+            label = col['label']
+        sortable = 'false'
+        if 'sortable' in col.keys():
+            sortable = str(col['sortable']).lower()
+        col_defs.append('{key:"%s",label:"%s",sortable:%s}' % (
+                key, label, sortable))
+    col_defs = ','.join(col_defs)
+    result = """
+    <script type="text/javascript">
+      var %sDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get("%s"));
+      %sDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
+      %sDataSource.responseSchema = {
+        fields: [%s
+                ]
+      };
+
+      var %sColumnDefs = [%s
+      ];
+
+      var %sDataTable = new YAHOO.widget.DataTable("%s", %sColumnDefs,
+                                                   %sDataSource);
+    </script>
+""" % (tableid, tableid, tableid, tableid, fielddefs, tableid, col_defs,
+       tableid, containerid, tableid, tableid)
+    return result



More information about the Checkins mailing list