import pyjd # this is dummy in pyjs.
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Button import Button
from pyjamas.ui.HTML import HTML
from pyjamas.ui.HorizontalPanel import HorizontalPanel
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.DockPanel import DockPanel
from pyjamas.ui.ScrollPanel import ScrollPanel
from pyjamas.ui.Grid import Grid
from pyjamas.ui.DisclosurePanel import DisclosurePanel

class OddGridWidget(DockPanel):

    def __init__(self, **kwargs):
        DockPanel.__init__(self, **kwargs)
        self.grid = Grid(StyleName="datagrid")
        self.sp = ScrollPanel(self.grid, Width="100%", Height="100%")
        self.header = Grid(Height="50px")
        self.add(self.header, DockPanel.NORTH)
        self.add(self.sp, DockPanel.CENTER)
        cf = self.setCellHeight(self.header, "50px")
        cf = self.setCellHeight(self.sp, "100%")

    def setData(self, data):
        rows = len(data)
        cols = 0
        if rows > 0:
            cols = len(data[0])
        self.grid.resize(rows, cols)
        for (nrow, row) in enumerate(data):
            for (ncol, item) in enumerate(row):
                self.grid.setHTML(nrow, ncol, str(item))

data = [["hello", "fred", 52],
        ["bye", "joe", 98],
        ["greetings", "alien", 0],
        ["sayonara", "jun", 1],
        ["gutentaag", "volker", 2],
        ["bonjour", "francois", 5],
        ["au reservoir", "fabrice", 8],
        ["go away", "mary", 73]
       ]

if __name__ == '__main__':
    pyjd.setup("public/SortedGridThing.html")
    ogw = OddGridWidget(Width="600px", Height="200px", StyleName="ogw")
    ogw.setData(data)
    RootPanel().add(ogw)
    pyjd.run()


@@ -891,16 +891,42 @@
 100%25%22)%0A%0A
+        self.sortcol = 0%0A%0A
     def 
@@ -942,24 +942,225 @@
 elf, data):%0A
+        self.data = data%0A        self.redraw()%0A%0A    def sortfn(self, row1, row2):%0A        return cmp(row1%5Bself.sortcol%5D, row2%5Bself.sortcol%5D)%0A%0A    def redraw(self):%0A        self.data.sort(self.sortfn)%0A%0A
         rows
@@ -1162,24 +1162,29 @@
  rows = len(
+self.
 data)%0A      
@@ -1238,16 +1238,21 @@
 s = len(
+self.
 data%5B0%5D)
@@ -1252,16 +1252,17 @@
 ata%5B0%5D)%0A
+%0A
         
@@ -1290,16 +1290,96 @@
 , cols)%0A
+        self.header.resize(1, cols)%0A%0A        cf = self.grid.getCellFormatter()%0A%0A
         
@@ -1407,16 +1407,21 @@
 umerate(
+self.
 data):%0A 
@@ -1523,16 +1523,566 @@
 r(item))
+%0A                cf.setWidth(nrow, ncol, %22200px%22)%0A%0A        cf = self.header.getCellFormatter()%0A        self.sortbuttons = %5B%5D%0A        for ncol in range(cols):%0A            sb = Button(%22sort col %25d%22 %25 ncol)%0A            sb.addClickListener(self)%0A            self.header.setWidget(0, ncol, sb)%0A            cf.setWidth(0, ncol, %22200px%22)%0A            self.sortbuttons.append(sb)%0A%0A    def onClick(self, sender):%0A        for (ncol, b) in enumerate(self.sortbuttons):%0A            if sender == b:%0A                self.sortcol = ncol%0A                self.redraw()
 %0A%0Adata =
@@ -2518,24 +2518,114 @@
 tData(data)%0A
+    dp = DisclosurePanel(%22Click to disclose / hide%22, True, Width=%22602px%22)%0A    dp.add(ogw)%0A
     RootPane
@@ -2628,27 +2628,26 @@
 Panel().add(
-ogw
+dp
 )%0A    pyjd.r

add sort buttons, disclosure panel