1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from pyjamas import DOM
16 from pyjamas import Factory
17
18 from HTMLTable import HTMLTable
19 from CellFormatter import CellFormatter
20 from RowFormatter import RowFormatter
21
22 -class Grid(HTMLTable):
23
24 - def __init__(self, rows=0, columns=0, **kwargs):
25 self.numColumns = 0
26 self.numRows = 0
27 HTMLTable.__init__(self, **kwargs)
28 if rows > 0 or columns > 0:
29 self.resize(rows, columns)
30
34
35 - def resize(self, rows, columns):
38
40 if self.numColumns == columns:
41 return
42
43 if self.numColumns > columns:
44 for i in range(0, self.numRows):
45 for j in range(self.numColumns - 1, columns - 1, -1):
46 self.removeCell(i, j)
47 else:
48 for i in range(self.numRows):
49 for j in range(self.numColumns, columns):
50 self.insertCell(i, j)
51 self.numColumns = columns
52
54 if self.numRows == rows:
55 return
56
57 if self.numRows < rows:
58 self.addRows(self.getBodyElement(), rows - self.numRows, self.numColumns)
59 self.numRows = rows
60 else:
61 while self.numRows > rows:
62 self.removeRow(self.numRows - 1)
63
68
74
77
80
82 return self.numColumns
83
85 return self.numColumns
86
89
90 - def addRows(self, table, numRows, columns):
99
100 Factory.registerClass('pyjamas.ui.Grid', Grid)
101