1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
|
<?php
/**
* TDataGrid related class files.
* This file contains the definition of the following classes:
* TDataGrid, TDataGridItem, TDataGridItemCollection, TDataGridColumnCollection,
* TDataGridPagerStyle, TDataGridItemEventParameter,
* TDataGridCommandEventParameter, TDataGridSortCommandEventParameter,
* TDataGridPageChangedEventParameter
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
*/
/**
* Includes TBaseList, TPagedDataSource, TDummyDataSource and TTable classes
*/
Prado::using('System.Web.UI.WebControls.TBaseDataList');
Prado::using('System.Collections.TPagedDataSource');
Prado::using('System.Collections.TDummyDataSource');
Prado::using('System.Web.UI.WebControls.TTable');
Prado::using('System.Web.UI.WebControls.TPanel');
/**
* TDataGrid class
*
* TDataGrid represents a data bound and updatable grid control.
*
* To populate data into the datagrid, sets its {@link setDataSource DataSource}
* to a tabular data source and call {@link dataBind()}.
* Each row of data will be represented by an item in the {@link getItems Items}
* collection of the datagrid.
*
* An item can be at one of three states: browsing, selected and edit.
* The state determines how the item will be displayed. For example, if an item
* is in edit state, it may be displayed as a table row with input text boxes
* if the columns are of type {@link TBoundColumn}; and if in browsing state,
* they are displayed as static text.
*
* To change the state of an item, set {@link setEditItemIndex EditItemIndex}
* or {@link setSelectedItemIndex SelectedItemIndex} property.
*
* A datagrid is specified with a list of columns. Each column specifies how the corresponding
* table column will be displayed. For example, the header/footer text of that column,
* the cells in that column, and so on. The following column types are currently
* provided by the framework,
* - {@link TBoundColumn}, associated with a specific field in datasource and displays the corresponding data.
* - {@link TEditCommandColumn}, displaying edit/update/cancel command buttons
* - {@link TButtonColumn}, displaying generic command buttons that may be bound to specific field in datasource.
* - {@link THyperLinkColumn}, displaying a hyperlink that may be bound to specific field in datasource.
* - {@link TCheckBoxColumn}, displaying a checkbox that may be bound to specific field in datasource.
* - {@link TTemplateColumn}, displaying content based on templates.
*
* There are three ways to specify columns for a datagrid.
* <ul>
* <li>Automatically generated based on data source.
* By setting {@link setAutoGenerateColumns AutoGenerateColumns} to true,
* a list of columns will be automatically generated based on the schema of the data source.
* Each column corresponds to a column of the data.</li>
* <li>Specified in template. For example,
* <code>
* <com:TDataGrid ...>
* <com:TBoundColumn .../>
* <com:TEditCommandColumn .../>
* </com:TDataGrid>
* </code>
* </li>
* <li>Manually created in code. Columns can be manipulated via
* the {@link setColumns Columns} property of the datagrid. For example,
* <code>
* $column=new TBoundColumn;
* $datagrid->Columns[]=$column;
* </code>
* </li>
* </ul>
* Note, automatically generated columns cannot be accessed via
* the {@link getColumns Columns} property.
*
* TDataGrid supports sorting. If the {@link setAllowSorting AllowSorting}
* is set to true, a column with nonempty {@link setSortExpression SortExpression}
* will have its header text displayed as a clickable link button.
* Clicking on the link button will raise {@link onSortCommand OnSortCommand}
* event. You can respond to this event, sort the data source according
* to the event parameter, and then invoke {@link databind()} on the datagrid
* to show to end users the sorted data.
*
* TDataGrid supports paging. If the {@link setAllowPaging AllowPaging}
* is set to true, a pager will be displayed on top and/or bottom of the table.
* How the pager will be displayed is determined by the {@link getPagerStyle PagerStyle}
* property. Clicking on a pager button will raise an {@link onPageIndexChanged OnPageIndexChanged}
* event. You can respond to this event, specify the page to be displayed by
* setting {@link setCurrentPageIndex CurrentPageIndex}</b> property,
* and then invoke {@link databind()} on the datagrid to show to end users
* a new page of data.
*
* TDataGrid supports two kinds of paging. The first one is based on the number of data items in
* datasource. The number of pages {@link getPageCount PageCount} is calculated based
* the item number and the {@link setPageSize PageSize} property.
* The datagrid will manage which section of the data source to be displayed
* based on the {@link setCurrentPageIndex CurrentPageIndex} property.
* The second approach calculates the page number based on the
* {@link setVirtualItemCount VirtualItemCount} property and
* the {@link setPageSize PageSize} property. The datagrid will always
* display from the beginning of the datasource up to the number of
* {@link setPageSize PageSize} data items. This approach is especially
* useful when the datasource may contain too many data items to be managed by
* the datagrid efficiently.
*
* When the datagrid contains a button control that raises an {@link onCommand OnCommand}
* event, the event will be bubbled up to the datagrid control.
* If the event's command name is recognizable by the datagrid control,
* a corresponding item event will be raised. The following item events will be
* raised upon a specific command:
* - OnEditCommand, if CommandName=edit
* - OnCancelCommand, if CommandName=cancel
* - OnSelectCommand, if CommandName=select
* - OnDeleteCommand, if CommandName=delete
* - OnUpdateCommand, if CommandName=update
* - onPageIndexChanged, if CommandName=page
* - OnSortCommand, if CommandName=sort
* Note, an {@link onItemCommand OnItemCommand} event is raised in addition to
* the above specific command events.
*
* TDataGrid also raises an {@link onItemCreated OnItemCreated} event for
* every newly created datagrid item. You can respond to this event to customize
* the content or style of the newly created item.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGrid extends TBaseDataList implements INamingContainer
{
/**
* datagrid item types
*/
const IT_HEADER='Header';
const IT_FOOTER='Footer';
const IT_ITEM='Item';
const IT_SEPARATOR='Separator';
const IT_ALTERNATINGITEM='AlternatingItem';
const IT_EDITITEM='EditItem';
const IT_SELECTEDITEM='SelectedItem';
const IT_PAGER='Pager';
/**
* Command name that TDataGrid understands.
*/
const CMD_SELECT='Select';
const CMD_EDIT='Edit';
const CMD_UPDATE='Update';
const CMD_DELETE='Delete';
const CMD_CANCEL='Cancel';
const CMD_SORT='Sort';
const CMD_PAGE='Page';
const CMD_PAGE_NEXT='Next';
const CMD_PAGE_PREV='Previous';
/**
* @var TDataGridColumnCollection manually created column collection
*/
private $_columns=null;
/**
* @var TDataGridColumnCollection automatically created column collection
*/
private $_autoColumns=null;
/**
* @var TDataGridItemCollection datagrid item collection
*/
private $_items=null;
/**
* @var TDataGridItem header item
*/
private $_header=null;
/**
* @var TDataGridItem footer item
*/
private $_footer=null;
/**
* @var TPagedDataSource paged data source object
*/
private $_pagedDataSource=null;
private $_topPager=null;
private $_bottomPager=null;
/**
* @var ITemplate template used when empty data is bounded
*/
private $_emptyTemplate=null;
/**
* @var boolean whether empty template is effective
*/
private $_useEmptyTemplate=false;
/**
* @return string tag name (table) of the datagrid
*/
protected function getTagName()
{
return 'table';
}
/**
* Adds objects parsed in template to datagrid.
* Datagrid columns are added into {@link getColumns Columns} collection.
* @param mixed object parsed in template
*/
public function addParsedObject($object)
{
if($object instanceof TDataGridColumn)
$this->getColumns()->add($object);
else
parent::addParsedObject($object);
}
/**
* @return TDataGridColumnCollection manually specified datagrid columns
*/
public function getColumns()
{
if(!$this->_columns)
$this->_columns=new TDataGridColumnCollection($this);
return $this->_columns;
}
/**
* @return TDataGridColumnCollection automatically generated datagrid columns
*/
public function getAutoColumns()
{
if(!$this->_autoColumns)
$this->_autoColumns=new TDataGridColumnCollection($this);
return $this->_autoColumns;
}
/**
* @return TDataGridItemCollection datagrid item collection
*/
public function getItems()
{
if(!$this->_items)
$this->_items=new TDataGridItemCollection;
return $this->_items;
}
/**
* Creates a style object for the control.
* This method creates a {@link TTableStyle} to be used by datagrid.
* @return TTableStyle control style to be used
*/
protected function createStyle()
{
$style=new TTableStyle;
$style->setGridLines('Both');
$style->setCellSpacing(0);
return $style;
}
/**
* @return string the URL of the background image for the datagrid
*/
public function getBackImageUrl()
{
return $this->getStyle()->getBackImageUrl();
}
/**
* @param string the URL of the background image for the datagrid
*/
public function setBackImageUrl($value)
{
$this->getStyle()->setBackImageUrl($value);
}
/**
* @return TTableItemStyle the style for every item
*/
public function getItemStyle()
{
if(($style=$this->getViewState('ItemStyle',null))===null)
{
$style=new TTableItemStyle;
$this->setViewState('ItemStyle',$style,null);
}
return $style;
}
/**
* @return TTableItemStyle the style for each alternating item
*/
public function getAlternatingItemStyle()
{
if(($style=$this->getViewState('AlternatingItemStyle',null))===null)
{
$style=new TTableItemStyle;
$this->setViewState('AlternatingItemStyle',$style,null);
}
return $style;
}
/**
* @return TTableItemStyle the style for selected item
*/
public function getSelectedItemStyle()
{
if(($style=$this->getViewState('SelectedItemStyle',null))===null)
{
$style=new TTableItemStyle;
$this->setViewState('SelectedItemStyle',$style,null);
}
return $style;
}
/**
* @return TTableItemStyle the style for edit item
*/
public function getEditItemStyle()
{
if(($style=$this->getViewState('EditItemStyle',null))===null)
{
$style=new TTableItemStyle;
$this->setViewState('EditItemStyle',$style,null);
}
return $style;
}
/**
* @return TTableItemStyle the style for header
*/
public function getHeaderStyle()
{
if(($style=$this->getViewState('HeaderStyle',null))===null)
{
$style=new TTableItemStyle;
$this->setViewState('HeaderStyle',$style,null);
}
return $style;
}
/**
* @return TTableItemStyle the style for footer
*/
public function getFooterStyle()
{
if(($style=$this->getViewState('FooterStyle',null))===null)
{
$style=new TTableItemStyle;
$this->setViewState('FooterStyle',$style,null);
}
return $style;
}
/**
* @return TDataGridPagerStyle the style for pager
*/
public function getPagerStyle()
{
if(($style=$this->getViewState('PagerStyle',null))===null)
{
$style=new TDataGridPagerStyle;
$this->setViewState('PagerStyle',$style,null);
}
return $style;
}
/**
* @return string caption for the datagrid
*/
public function getCaption()
{
return $this->getViewState('Caption','');
}
/**
* @param string caption for the datagrid
*/
public function setCaption($value)
{
$this->setViewState('Caption',$value,'');
}
/**
* @return string datagrid caption alignment. Defaults to 'NotSet'.
*/
public function getCaptionAlign()
{
return $this->getViewState('CaptionAlign','NotSet');
}
/**
* @param string datagrid caption alignment. Valid values include
* 'NotSet','Top','Bottom','Left','Right'.
*/
public function setCaptionAlign($value)
{
$this->setViewState('CaptionAlign',TPropertyValue::ensureEnum($value,'NotSet','Top','Bottom','Left','Right'),'NotSet');
}
/**
* @return TDataGridItem the header item
*/
public function getHeader()
{
return $this->_header;
}
/**
* @return TDataGridItem the footer item
*/
public function getFooter()
{
return $this->_footer;
}
/**
* @return TDataGridPager the pager displayed at the top of datagrid. It could be null if paging is disabled.
*/
public function getTopPager()
{
return $this->_topPager;
}
/**
* @return TDataGridPager the pager displayed at the bottom of datagrid. It could be null if paging is disabled.
*/
public function getBottomPager()
{
return $this->_bottomPager;
}
/**
* @return TDataGridItem the selected item, null if no item is selected.
*/
public function getSelectedItem()
{
$index=$this->getSelectedItemIndex();
$items=$this->getItems();
if($index>=0 && $index<$items->getCount())
return $items->itemAt($index);
else
return null;
}
/**
* @return integer the zero-based index of the selected item in {@link getItems Items}.
* A value -1 means no item selected.
*/
public function getSelectedItemIndex()
{
return $this->getViewState('SelectedItemIndex',-1);
}
/**
* Selects an item by its index in {@link getItems Items}.
* Previously selected item will be un-selected.
* If the item to be selected is already in edit mode, it will remain in edit mode.
* If the index is less than 0, any existing selection will be cleared up.
* @param integer the selected item index
*/
public function setSelectedItemIndex($value)
{
if(($value=TPropertyValue::ensureInteger($value))<0)
$value=-1;
if(($current=$this->getSelectedItemIndex())!==$value)
{
$this->setViewState('SelectedItemIndex',$value,-1);
$items=$this->getItems();
$itemCount=$items->getCount();
if($current>=0 && $current<$itemCount)
{
$item=$items->itemAt($current);
if($item->getItemType()!==self::IT_EDITITEM)
$item->setItemType($current%2?self::IT_ALTERNATINGITEM:self::IT_ITEM);
}
if($value>=0 && $value<$itemCount)
{
$item=$items->itemAt($value);
if($item->getItemType()!==self::IT_EDITITEM)
$item->setItemType(self::IT_SELECTEDITEM);
}
}
}
/**
* @return TDataGridItem the edit item
*/
public function getEditItem()
{
$index=$this->getEditItemIndex();
$items=$this->getItems();
if($index>=0 && $index<$items->getCount())
return $items->itemAt($index);
else
return null;
}
/**
* @return integer the zero-based index of the edit item in {@link getItems Items}.
* A value -1 means no item is in edit mode.
*/
public function getEditItemIndex()
{
return $this->getViewState('EditItemIndex',-1);
}
/**
* Edits an item by its index in {@link getItems Items}.
* Previously editting item will change to normal item state.
* If the index is less than 0, any existing edit item will be cleared up.
* @param integer the edit item index
*/
public function setEditItemIndex($value)
{
if(($value=TPropertyValue::ensureInteger($value))<0)
$value=-1;
if(($current=$this->getEditItemIndex())!==$value)
{
$this->setViewState('EditItemIndex',$value,-1);
$items=$this->getItems();
$itemCount=$items->getCount();
if($current>=0 && $current<$itemCount)
$items->itemAt($current)->setItemType($current%2?self::IT_ALTERNATINGITEM:self::IT_ITEM);
if($value>=0 && $value<$itemCount)
$items->itemAt($value)->setItemType(self::IT_EDITITEM);
}
}
/**
* @return boolean whether the custom paging is enabled. Defaults to false.
*/
public function getAllowCustomPaging()
{
return $this->getViewState('AllowCustomPaging',false);
}
/**
* @param boolean whether the custom paging is enabled
*/
public function setAllowCustomPaging($value)
{
$this->setViewState('AllowCustomPaging',TPropertyValue::ensureBoolean($value),false);
}
/**
* @return boolean whether paging is enabled. Defaults to false.
*/
public function getAllowPaging()
{
return $this->getViewState('AllowPaging',false);
}
/**
* @return boolean whether sorting is enabled. Defaults to false.
*/
public function getAllowSorting()
{
return $this->getViewState('AllowSorting',false);
}
/**
* @param boolean whether paging is enabled
*/
public function setAllowPaging($value)
{
$this->setViewState('AllowPaging',TPropertyValue::ensureBoolean($value),false);
}
/**
* @param boolean whether sorting is enabled
*/
public function setAllowSorting($value)
{
$this->setViewState('AllowSorting',TPropertyValue::ensureBoolean($value),false);
}
/**
* @return boolean whether datagrid columns should be automatically generated. Defaults to true.
*/
public function getAutoGenerateColumns()
{
return $this->getViewState('AutoGenerateColumns',true);
}
/**
* @param boolean whether datagrid columns should be automatically generated
*/
public function setAutoGenerateColumns($value)
{
$this->setViewState('AutoGenerateColumns',TPropertyValue::ensureBoolean($value),true);
}
/**
* @return integer the zero-based index of the current page. Defaults to 0.
*/
public function getCurrentPageIndex()
{
return $this->getViewState('CurrentPageIndex',0);
}
/**
* @param integer the zero-based index of the current page
* @throws TInvalidDataValueException if the value is less than 0
*/
public function setCurrentPageIndex($value)
{
if(($value=TPropertyValue::ensureInteger($value))<0)
throw new TInvalidDataValueException('datagrid_currentpageindex_invalid');
$this->setViewState('CurrentPageIndex',$value,0);
}
/**
* @return integer the number of rows displayed each page. Defaults to 10.
*/
public function getPageSize()
{
return $this->getViewState('PageSize',10);
}
/**
* @param integer the number of rows displayed within a page
* @throws TInvalidDataValueException if the value is less than 1
*/
public function setPageSize($value)
{
if(($value=TPropertyValue::ensureInteger($value))<1)
throw new TInvalidDataValueException('datagrid_pagesize_invalid');
$this->setViewState('PageSize',TPropertyValue::ensureInteger($value),10);
}
/**
* @return integer number of pages of items available
*/
public function getPageCount()
{
if($this->_pagedDataSource)
return $this->_pagedDataSource->getPageCount();
else
return $this->getViewState('PageCount',0);
}
/**
* @return integer virtual number of items in the grid. Defaults to 0, meaning not set.
*/
public function getVirtualItemCount()
{
return $this->getViewState('VirtualItemCount',0);
}
/**
* @param integer virtual number of items in the grid
* @throws TInvalidDataValueException if the value is less than 0
*/
public function setVirtualItemCount($value)
{
if(($value=TPropertyValue::ensureInteger($value))<0)
throw new TInvalidDataValueException('datagrid_virtualitemcount_invalid');
$this->setViewState('VirtualItemCount',$value,0);
}
/**
* @return boolean whether the header should be displayed. Defaults to true.
*/
public function getShowHeader()
{
return $this->getViewState('ShowHeader',true);
}
/**
* @param boolean whether the header should be displayed
*/
public function setShowHeader($value)
{
$this->setViewState('ShowHeader',TPropertyValue::ensureBoolean($value),true);
}
/**
* @return boolean whether the footer should be displayed. Defaults to false.
*/
public function getShowFooter()
{
return $this->getViewState('ShowFooter',false);
}
/**
* @param boolean whether the footer should be displayed
*/
public function setShowFooter($value)
{
$this->setViewState('ShowFooter',TPropertyValue::ensureBoolean($value),false);
}
/**
* @return ITemplate the template applied when no data is bound to the datagrid
*/
public function getEmptyTemplate()
{
return $this->_emptyTemplate;
}
/**
* @param ITemplate the template applied when no data is bound to the datagrid
* @throws TInvalidDataTypeException if the input is not an {@link ITemplate} or not null.
*/
public function setEmptyTemplate($value)
{
if($value instanceof ITemplate || $value===null)
$this->_emptyTemplate=$value;
else
throw new TInvalidDataTypeException('datagrid_template_required','EmptyTemplate');
}
/**
* This method overrides parent's implementation to handle
* {@link onItemCommand OnItemCommand} event which is bubbled from
* {@link TDataGridItem} child controls.
* If the event parameter is {@link TDataGridCommandEventParameter} and
* the command name is a recognized one, which includes 'select', 'edit',
* 'delete', 'update', and 'cancel' (case-insensitive), then a
* corresponding command event is also raised (such as {@link onEditCommand OnEditCommand}).
* This method should only be used by control developers.
* @param TControl the sender of the event
* @param TEventParameter event parameter
* @return boolean whether the event bubbling should stop here.
*/
public function bubbleEvent($sender,$param)
{
if($param instanceof TDataGridCommandEventParameter)
{
$this->onItemCommand($param);
$command=$param->getCommandName();
if(strcasecmp($command,self::CMD_SELECT)===0)
{
$this->setSelectedItemIndex($param->getItem()->getItemIndex());
$this->onSelectedIndexChanged(null);
return true;
}
else if(strcasecmp($command,self::CMD_EDIT)===0)
{
$this->onEditCommand($param);
return true;
}
else if(strcasecmp($command,self::CMD_DELETE)===0)
{
$this->onDeleteCommand($param);
return true;
}
else if(strcasecmp($command,self::CMD_UPDATE)===0)
{
$this->onUpdateCommand($param);
return true;
}
else if(strcasecmp($command,self::CMD_CANCEL)===0)
{
$this->onCancelCommand($param);
return true;
}
else if(strcasecmp($command,self::CMD_SORT)===0)
{
$this->onSortCommand(new TDataGridSortCommandEventParameter($sender,$param));
return true;
}
else if(strcasecmp($command,self::CMD_PAGE)===0)
{
$p=$param->getCommandParameter();
if(strcasecmp($p,self::CMD_PAGE_NEXT)===0)
$pageIndex=$this->getCurrentPageIndex()+1;
else if(strcasecmp($p,self::CMD_PAGE_PREV)===0)
$pageIndex=$this->getCurrentPageIndex()-1;
else
$pageIndex=TPropertyValue::ensureInteger($p)-1;
$this->onPageIndexChanged(new TDataGridPageChangedEventParameter($sender,$pageIndex));
return true;
}
}
return false;
}
/**
* Raises <b>OnCancelCommand</b> event.
* This method is invoked when a button control raises <b>OnCommand</b> event
* with <b>cancel</b> command name.
* @param TDataGridCommandEventParameter event parameter
*/
public function onCancelCommand($param)
{
$this->raiseEvent('OnCancelCommand',$this,$param);
}
/**
* Raises <b>OnDeleteCommand</b> event.
* This method is invoked when a button control raises <b>OnCommand</b> event
* with <b>delete</b> command name.
* @param TDataGridCommandEventParameter event parameter
*/
public function onDeleteCommand($param)
{
$this->raiseEvent('OnDeleteCommand',$this,$param);
}
/**
* Raises <b>OnEditCommand</b> event.
* This method is invoked when a button control raises <b>OnCommand</b> event
* with <b>edit</b> command name.
* @param TDataGridCommandEventParameter event parameter
*/
public function onEditCommand($param)
{
$this->raiseEvent('OnEditCommand',$this,$param);
}
/**
* Raises <b>OnItemCommand</b> event.
* This method is invoked when a button control raises <b>OnCommand</b> event.
* @param TDataGridCommandEventParameter event parameter
*/
public function onItemCommand($param)
{
$this->raiseEvent('OnItemCommand',$this,$param);
}
/**
* Raises <b>OnSortCommand</b> event.
* This method is invoked when a button control raises <b>OnCommand</b> event
* with <b>sort</b> command name.
* @param TDataGridSortCommandEventParameter event parameter
*/
public function onSortCommand($param)
{
$this->raiseEvent('OnSortCommand',$this,$param);
}
/**
* Raises <b>OnUpdateCommand</b> event.
* This method is invoked when a button control raises <b>OnCommand</b> event
* with <b>update</b> command name.
* @param TDataGridCommandEventParameter event parameter
*/
public function onUpdateCommand($param)
{
$this->raiseEvent('OnUpdateCommand',$this,$param);
}
/**
* Raises <b>OnItemCreated</b> event.
* This method is invoked right after a datagrid item is created and before
* added to page hierarchy.
* @param TDataGridItemEventParameter event parameter
*/
public function onItemCreated($param)
{
$this->raiseEvent('OnItemCreated',$this,$param);
}
/**
* Raises <b>OnPagerCreated</b> event.
* This method is invoked right after a datagrid pager is created and before
* added to page hierarchy.
* @param TDataGridPagerEventParameter event parameter
*/
public function onPagerCreated($param)
{
$this->raiseEvent('OnPagerCreated',$this,$param);
}
/**
* Raises <b>OnItemDataBound</b> event.
* This method is invoked for each datagrid item after it performs
* databinding.
* @param TDataGridItemEventParameter event parameter
*/
public function onItemDataBound($param)
{
$this->raiseEvent('OnItemDataBound',$this,$param);
}
/**
* Raises <b>OnPageIndexChanged</b> event.
* This method is invoked when current page is changed.
* @param TDataGridPageChangedEventParameter event parameter
*/
public function onPageIndexChanged($param)
{
$this->raiseEvent('OnPageIndexChanged',$this,$param);
}
/**
* Saves item count in viewstate.
* This method is invoked right before control state is to be saved.
*/
public function saveState()
{
parent::saveState();
if(!$this->getEnableViewState(true))
return;
if($this->_items)
$this->setViewState('ItemCount',$this->_items->getCount(),0);
else
$this->clearViewState('ItemCount');
if($this->_autoColumns)
{
$state=array();
foreach($this->_autoColumns as $column)
$state[]=$column->saveState();
$this->setViewState('AutoColumns',$state,array());
}
else
$this->clearViewState('AutoColumns');
if($this->_columns)
{
$state=array();
foreach($this->_columns as $column)
$state[]=$column->saveState();
$this->setViewState('Columns',$state,array());
}
else
$this->clearViewState('Columns');
}
/**
* Loads item count information from viewstate.
* This method is invoked right after control state is loaded.
*/
public function loadState()
{
parent::loadState();
if(!$this->getEnableViewState(true))
return;
if(!$this->getIsDataBound())
{
$state=$this->getViewState('AutoColumns',array());
if(!empty($state))
{
$this->_autoColumns=new TDataGridColumnCollection($this);
foreach($state as $st)
{
$column=new TBoundColumn;
$column->loadState($st);
$this->_autoColumns->add($column);
}
}
else
$this->_autoColumns=null;
$state=$this->getViewState('Columns',array());
if($this->_columns && $this->_columns->getCount()===count($state))
{
$i=0;
foreach($this->_columns as $column)
{
$column->loadState($state[$i]);
$i++;
}
}
$this->restoreGridFromViewState();
}
$this->clearViewState('ItemCount');
}
/**
* @return TPagedDataSource creates a paged data source
*/
private function createPagedDataSource()
{
$ds=new TPagedDataSource;
$ds->setCurrentPageIndex($this->getCurrentPageIndex());
$ds->setPageSize($this->getPageSize());
$ds->setAllowPaging($this->getAllowPaging());
$ds->setAllowCustomPaging($this->getAllowCustomPaging());
$ds->setVirtualItemCount($this->getVirtualItemCount());
return $ds;
}
/**
* Clears up all items in the datagrid.
*/
public function reset()
{
$this->getControls()->clear();
$this->getItems()->clear();
$this->_header=null;
$this->_footer=null;
$this->_topPager=null;
$this->_bottomPager=null;
$this->_useEmptyTemplate=false;
}
/**
* Restores datagrid content from viewstate.
*/
protected function restoreGridFromViewState()
{
$this->reset();
$itemCount=$this->getViewState('ItemCount',0);
$this->_pagedDataSource=$ds=$this->createPagedDataSource();
$allowPaging=$ds->getAllowPaging();
if($allowPaging && $ds->getAllowCustomPaging())
$ds->setDataSource(new TDummyDataSource($itemCount));
else
$ds->setDataSource(new TDummyDataSource($this->getViewState('DataSourceCount',0)));
if($ds->getCount()===0 && $ds->getCurrentPageIndex()===0 && $this->_emptyTemplate!==null)
{
$this->_emptyTemplate->instantiateIn($this);
$this->_useEmptyTemplate=true;
$this->clearViewState('ItemCount');
$this->clearViewState('PageCount');
$this->clearViewState('DataSourceCount');
return;
}
$columns=new TList($this->getColumns());
$columns->mergeWith($this->_autoColumns);
$items=$this->getItems();
$items->clear();
if($columns->getCount())
{
foreach($columns as $column)
$column->initialize();
if($allowPaging)
$this->_topPager=$this->createPager($ds);
$this->_header=$this->createItemInternal(-1,-1,self::IT_HEADER,false,null,$columns);
$selectedIndex=$this->getSelectedItemIndex();
$editIndex=$this->getEditItemIndex();
$index=0;
$dsIndex=$ds->getAllowPaging()?$ds->getFirstIndexInPage():0;
foreach($ds as $data)
{
if($index===$editIndex)
$itemType=self::IT_EDITITEM;
else if($index===$selectedIndex)
$itemType=self::IT_SELECTEDITEM;
else if($index % 2)
$itemType=self::IT_ALTERNATINGITEM;
else
$itemType=self::IT_ITEM;
$items->add($this->createItemInternal($index,$dsIndex,$itemType,false,null,$columns));
$index++;
$dsIndex++;
}
$this->_footer=$this->createItemInternal(-1,-1,self::IT_FOOTER,false,null,$columns);
if($allowPaging)
$this->_bottomPager=$this->createPager($ds);
}
$this->_pagedDataSource=null;
}
/**
* Performs databinding to populate data list items from data source.
* This method is invoked by {@link dataBind()}.
* You may override this function to provide your own way of data population.
* @param Traversable the bound data
*/
protected function performDataBinding($data)
{
$this->reset();
$keys=$this->getDataKeys();
$keys->clear();
$keyField=$this->getDataKeyField();
$this->_pagedDataSource=$ds=$this->createPagedDataSource();
$ds->setDataSource($data);
$allowPaging=$ds->getAllowPaging();
if($allowPaging && $ds->getCurrentPageIndex()>=$ds->getPageCount())
throw new TInvalidDataValueException('datagrid_currentpageindex_invalid');
if($ds->getCount()===0 && $ds->getCurrentPageIndex()===0 && $this->_emptyTemplate!==null)
{
$this->_useEmptyTemplate=true;
$this->_emptyTemplate->instantiateIn($this);
$this->dataBindChildren();
$this->clearViewState('ItemCount');
$this->clearViewState('PageCount');
$this->clearViewState('DataSourceCount');
return;
}
// get all columns
if($this->getAutoGenerateColumns())
{
$columns=new TList($this->getColumns());
$autoColumns=$this->createAutoColumns($ds);
$columns->mergeWith($autoColumns);
}
else
$columns=$this->getColumns();
$items=$this->getItems();
if($columns->getCount())
{
foreach($columns as $column)
$column->initialize();
$allowPaging=$ds->getAllowPaging();
if($allowPaging)
$this->_topPager=$this->createPager($ds);
$this->_header=$this->createItemInternal(-1,-1,self::IT_HEADER,true,null,$columns);
$selectedIndex=$this->getSelectedItemIndex();
$editIndex=$this->getEditItemIndex();
$index=0;
$dsIndex=$allowPaging?$ds->getFirstIndexInPage():0;
foreach($ds as $key=>$data)
{
if($keyField!=='')
$keys->add($this->getDataFieldValue($data,$keyField));
else
$keys->add($key);
if($index===$editIndex)
$itemType=self::IT_EDITITEM;
else if($index===$selectedIndex)
$itemType=self::IT_SELECTEDITEM;
else if($index % 2)
$itemType=self::IT_ALTERNATINGITEM;
else
$itemType=self::IT_ITEM;
$items->add($this->createItemInternal($index,$dsIndex,$itemType,true,$data,$columns));
$index++;
$dsIndex++;
}
$this->_footer=$this->createItemInternal(-1,-1,self::IT_FOOTER,true,null,$columns);
if($allowPaging)
$this->_bottomPager=$this->createPager($ds);
$this->setViewState('ItemCount',$index,0);
$this->setViewState('PageCount',$ds->getPageCount(),0);
$this->setViewState('DataSourceCount',$ds->getDataSourceCount(),0);
}
else
{
$this->clearViewState('ItemCount');
$this->clearViewState('PageCount');
$this->clearViewState('DataSourceCount');
}
$this->_pagedDataSource=null;
}
/**
* Creates a datagrid item instance based on the item type and index.
* @param integer zero-based item index
* @param string item type, may be self::IT_HEADER, self::IT_FOOTER, self::IT_ITEM, self::IT_SEPARATOR, self::IT_ALTERNATINGITEM, self::IT_SELECTEDITEM, self::IT_EDITITEM.
* @return TDataGridItem created data list item
*/
protected function createItem($itemIndex,$dataSourceIndex,$itemType)
{
return new TDataGridItem($itemIndex,$dataSourceIndex,$itemType);
}
private function createItemInternal($itemIndex,$dataSourceIndex,$itemType,$dataBind,$dataItem,$columns)
{
$item=$this->createItem($itemIndex,$dataSourceIndex,$itemType);
$this->initializeItem($item,$columns);
$param=new TDataGridItemEventParameter($item);
if($dataBind)
{
$item->setDataItem($dataItem);
$this->onItemCreated($param);
$this->getControls()->add($item);
$item->dataBind();
$this->onItemDataBound($param);
$item->setDataItem(null);
}
else
{
$this->onItemCreated($param);
$this->getControls()->add($item);
}
return $item;
}
/**
* Initializes a datagrid item and cells inside it
* @param TDataGrid datagrid item to be initialized
* @param TDataGridColumnCollection datagrid columns to be used to initialize the cells in the item
*/
protected function initializeItem($item,$columns)
{
$cells=$item->getCells();
$itemType=$item->getItemType();
$index=0;
foreach($columns as $column)
{
if($itemType===self::IT_HEADER)
$cell=new TTableHeaderCell;
else
$cell=new TTableCell;
$column->initializeCell($cell,$index,$itemType);
$cells->add($cell);
$index++;
}
}
private function createPager($pagedDataSource)
{
$pager=new TDataGridPager($this);
$this->buildPager($pager,$pagedDataSource);
$this->onPagerCreated(new TDataGridPagerEventParameter($pager));
$this->getControls()->add($pager);
return $pager;
}
/**
* Builds the pager content based on pager style.
* @param TDataGridPager the container for the pager
* @param TPagedDataSource data source bound to the datagrid
*/
protected function buildPager($pager,$dataSource)
{
switch($this->getPagerStyle()->getMode())
{
case 'NextPrev':
$this->buildNextPrevPager($pager,$dataSource);
break;
case 'Numeric':
$this->buildNumericPager($pager,$dataSource);
break;
}
}
/**
* Creates a pager button.
* @param string button type, LinkButton or PushButton
* @param boolean whether the button should be enabled
* @return mixed the button instance
*/
protected function createPagerButton($buttonType,$enabled)
{
if($buttonType==='LinkButton')
{
return $enabled?new TLinkButton:new TLabel;
}
else
{
$button=new TButton;
if(!$enabled)
$button->setEnabled(false);
return $button;
}
}
/**
* Builds a next-prev pager
* @param TDataGridPager the container for the pager
* @param TPagedDataSource data source bound to the datagrid
*/
protected function buildNextPrevPager($pager,$dataSource)
{
$style=$this->getPagerStyle();
$buttonType=$style->getButtonType();
$controls=$pager->getControls();
if($dataSource->getIsFirstPage())
{
$label=$this->createPagerButton($buttonType,false);
$label->setText($style->getPrevPageText());
$controls->add($label);
}
else
{
$button=$this->createPagerButton($buttonType,true);
$button->setText($style->getPrevPageText());
$button->setCommandName(self::CMD_PAGE);
$button->setCommandParameter(self::CMD_PAGE_PREV);
$button->setCausesValidation(false);
$controls->add($button);
}
$controls->add(' ');
if($dataSource->getIsLastPage())
{
$label=$this->createPagerButton($buttonType,false);
$label->setText($style->getNextPageText());
$controls->add($label);
}
else
{
$button=$this->createPagerButton($buttonType,true);
$button->setText($style->getNextPageText());
$button->setCommandName(self::CMD_PAGE);
$button->setCommandParameter(self::CMD_PAGE_NEXT);
$button->setCausesValidation(false);
$controls->add($button);
}
}
/**
* Builds a numeric pager
* @param TDataGridPager the container for the pager
* @param TPagedDataSource data source bound to the datagrid
*/
protected function buildNumericPager($pager,$dataSource)
{
$style=$this->getPagerStyle();
$buttonType=$style->getButtonType();
$controls=$pager->getControls();
$pageCount=$dataSource->getPageCount();
$pageIndex=$dataSource->getCurrentPageIndex()+1;
$maxButtonCount=$style->getPageButtonCount();
$buttonCount=$maxButtonCount>$pageCount?$pageCount:$maxButtonCount;
$startPageIndex=1;
$endPageIndex=$buttonCount;
if($pageIndex>$endPageIndex)
{
$startPageIndex=((int)(($pageIndex-1)/$maxButtonCount))*$maxButtonCount+1;
if(($endPageIndex=$startPageIndex+$maxButtonCount-1)>$pageCount)
$endPageIndex=$pageCount;
if($endPageIndex-$startPageIndex+1<$maxButtonCount)
{
if(($startPageIndex=$endPageIndex-$maxButtonCount+1)<1)
$startPageIndex=1;
}
}
if($startPageIndex>1)
{
$button=$this->createPagerButton($buttonType,true);
$button->setText($style->getPrevPageText());
$button->setCommandName(self::CMD_PAGE);
$button->setCommandParameter($startPageIndex-1);
$button->setCausesValidation(false);
$controls->add($button);
$controls->add(' ');
}
for($i=$startPageIndex;$i<=$endPageIndex;++$i)
{
if($i===$pageIndex)
{
$label=$this->createPagerButton($buttonType,false);
$label->setText("$i");
$controls->add($label);
}
else
{
$button=$this->createPagerButton($buttonType,true);
$button->setText("$i");
$button->setCommandName(self::CMD_PAGE);
$button->setCommandParameter($i);
$button->setCausesValidation(false);
$controls->add($button);
}
if($i<$endPageIndex)
$controls->add(' ');
}
if($pageCount>$endPageIndex)
{
$controls->add(' ');
$button=$this->createPagerButton($buttonType,true);
$button->setText($style->getNextPageText());
$button->setCommandName(self::CMD_PAGE);
$button->setCommandParameter($endPageIndex+1);
$button->setCausesValidation(false);
$controls->add($button);
}
}
/**
* Automatically generates datagrid columns based on datasource schema
* @param TPagedDataSource data source bound to the datagrid
* @return TDataGridColumnCollection
*/
protected function createAutoColumns($dataSource)
{
if(!$dataSource)
return null;
$autoColumns=$this->getAutoColumns();
$autoColumns->clear();
foreach($dataSource as $row)
{
foreach($row as $key=>$value)
{
$column=new TBoundColumn;
if(is_string($key))
{
$column->setHeaderText($key);
$column->setDataField($key);
$column->setSortExpression($key);
$autoColumns->add($column);
}
else
{
$column->setHeaderText(self::IT_ITEM);
$column->setDataField($key);
$column->setSortExpression(self::IT_ITEM);
$autoColumns->add($column);
}
}
break;
}
return $autoColumns;
}
/**
* Applies styles to items, header, footer and separators.
* Item styles are applied in a hierarchical way. Style in higher hierarchy
* will inherit from styles in lower hierarchy.
* Starting from the lowest hierarchy, the item styles include
* item's own style, {@link getItemStyle ItemStyle}, {@link getAlternatingItemStyle AlternatingItemStyle},
* {@link getSelectedItemStyle SelectedItemStyle}, and {@link getEditItemStyle EditItemStyle}.
* Therefore, if background color is set as red in {@link getItemStyle ItemStyle},
* {@link getEditItemStyle EditItemStyle} will also have red background color
* unless it is set to a different value explicitly.
*/
protected function applyItemStyles()
{
$itemStyle=$this->getViewState('ItemStyle',null);
$alternatingItemStyle=$this->getViewState('AlternatingItemStyle',null);
if($itemStyle!==null)
{
if($alternatingItemStyle===null)
$alternatingItemStyle=$itemStyle;
else
$alternatingItemStyle->mergeWith($itemStyle);
}
$selectedItemStyle=$this->getViewState('SelectedItemStyle',null);
$editItemStyle=$this->getViewState('EditItemStyle',null);
if($selectedItemStyle!==null)
{
if($editItemStyle===null)
$editItemStyle=$selectedItemStyle;
else
$editItemStyle->mergeWith($selectedItemStyle);
}
$headerStyle=$this->getViewState('HeaderStyle',null);
$footerStyle=$this->getViewState('FooterStyle',null);
$pagerStyle=$this->getViewState('PagerStyle',null);
$separatorStyle=$this->getViewState('SeparatorStyle',null);
foreach($this->getControls() as $index=>$item)
{
$itemType=$item->getItemType();
switch($itemType)
{
case self::IT_HEADER:
if($headerStyle)
$item->getStyle()->mergeWith($headerStyle);
if(!$this->getShowHeader())
$item->setVisible(false);
break;
case self::IT_FOOTER:
if($footerStyle)
$item->getStyle()->mergeWith($footerStyle);
if(!$this->getShowFooter())
$item->setVisible(false);
break;
case self::IT_SEPARATOR:
if($separatorStyle)
$item->getStyle()->mergeWith($separatorStyle);
break;
case self::IT_ITEM:
if($itemStyle)
$item->getStyle()->mergeWith($itemStyle);
break;
case self::IT_ALTERNATINGITEM:
if($alternatingItemStyle)
$item->getStyle()->mergeWith($alternatingItemStyle);
break;
case self::IT_SELECTEDITEM:
if($selectedItemStyle)
$item->getStyle()->mergeWith($selectedItemStyle);
if($index % 2==1)
{
if($itemStyle)
$item->getStyle()->mergeWith($itemStyle);
}
else
{
if($alternatingItemStyle)
$item->getStyle()->mergeWith($alternatingItemStyle);
}
break;
case self::IT_EDITITEM:
if($editItemStyle)
$item->getStyle()->mergeWith($editItemStyle);
if($index % 2==1)
{
if($itemStyle)
$item->getStyle()->mergeWith($itemStyle);
}
else
{
if($alternatingItemStyle)
$item->getStyle()->mergeWith($alternatingItemStyle);
}
break;
case self::IT_PAGER:
if($pagerStyle)
{
$item->getStyle()->mergeWith($pagerStyle);
if($index===0)
{
if($pagerStyle->getPosition()==='Bottom' || !$pagerStyle->getVisible())
$item->setVisible(false);
}
else
{
if($pagerStyle->getPosition()==='Top' || !$pagerStyle->getVisible())
$item->setVisible(false);
}
}
break;
default:
break;
}
if($this->_columns && $itemType!==self::IT_PAGER)
{
$n=$this->_columns->getCount();
$cells=$item->getCells();
for($i=0;$i<$n;++$i)
{
$cell=$cells->itemAt($i);
$column=$this->_columns->itemAt($i);
if(!$column->getVisible())
$cell->setVisible(false);
else
{
if($itemType===self::IT_HEADER)
$style=$column->getHeaderStyle(false);
else if($itemType===self::IT_FOOTER)
$style=$column->getFooterStyle(false);
else
$style=$column->getItemStyle(false);
if($style!==null)
$cell->getStyle()->mergeWith($style);
}
}
}
}
}
/**
* Renders the openning tag for the datagrid control which will render table caption if present.
* @param THtmlWriter the writer used for the rendering purpose
*/
public function renderBeginTag($writer)
{
parent::renderBeginTag($writer);
if(($caption=$this->getCaption())!=='')
{
if(($align=$this->getCaptionAlign())!=='NotSet')
$writer->addAttribute('align',strtolower($align));
$writer->renderBeginTag('caption');
$writer->write($caption);
$writer->renderEndTag();
}
}
/**
* Renders the datagrid.
* @param THtmlWriter writer for the rendering purpose
*/
public function render($writer)
{
if($this->getHasControls())
{
if($this->_useEmptyTemplate)
{
$control=new TWebControl;
$control->setID($this->getClientID());
$control->copyBaseAttributes($this);
if($this->getHasStyle())
$control->getStyle()->copyFrom($this->getStyle());
$control->renderBeginTag($writer);
$this->renderContents($writer);
$control->renderEndTag($writer);
}
else
{
$this->applyItemStyles();
if($this->_topPager)
{
$this->_topPager->renderControl($writer);
$writer->writeLine();
}
$this->renderTable($writer);
if($this->_bottomPager)
{
$writer->writeLine();
$this->_bottomPager->renderControl($writer);
}
}
}
}
/**
* Renders the tabular data.
* @param THtmlWriter writer
*/
protected function renderTable($writer)
{
$this->renderBeginTag($writer);
if($this->_header && $this->_header->getVisible())
{
$writer->writeLine();
$writer->renderBeginTag('thead');
$this->_header->render($writer);
$writer->renderEndTag();
}
$writer->writeLine();
$writer->renderBeginTag('tbody');
foreach($this->getItems() as $item)
$item->renderControl($writer);
$writer->renderEndTag();
if($this->_footer && $this->_footer->getVisible())
{
$writer->writeLine();
$writer->renderBeginTag('tfoot');
$this->_footer->render($writer);
$writer->renderEndTag();
}
$writer->writeLine();
$this->renderEndTag($writer);
}
}
/**
* TDataGridItemEventParameter class
*
* TDataGridItemEventParameter encapsulates the parameter data for
* {@link TDataGrid::onItemCreated OnItemCreated} event of {@link TDataGrid} controls.
* The {@link getItem Item} property indicates the datagrid item related with the event.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridItemEventParameter extends TEventParameter
{
/**
* The TDataGridItem control responsible for the event.
* @var TDataGridItem
*/
private $_item=null;
/**
* Constructor.
* @param TDataGridItem datagrid item related with the corresponding event
*/
public function __construct(TDataGridItem $item)
{
$this->_item=$item;
}
/**
* @return TDataGridItem datagrid item related with the corresponding event
*/
public function getItem()
{
return $this->_item;
}
}
/**
* TDataGridPagerEventParameter class
*
* TDataGridPagerEventParameter encapsulates the parameter data for
* {@link TDataGrid::onPagerCreated OnPagerCreated} event of {@link TDataGrid} controls.
* The {@link getPager Pager} property indicates the datagrid pager related with the event.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridPagerEventParameter extends TEventParameter
{
/**
* The TDataGridPager control responsible for the event.
* @var TDataGridPager
*/
private $_pager=null;
/**
* Constructor.
* @param TDataGridPager datagrid pager related with the corresponding event
*/
public function __construct(TDataGridPager $pager)
{
$this->_pager=$pager;
}
/**
* @return TDataGridPager datagrid pager related with the corresponding event
*/
public function getPager()
{
return $this->_pager;
}
}
/**
* TDataGridCommandEventParameter class
*
* TDataGridCommandEventParameter encapsulates the parameter data for
* {@link TDataGrid::onItemCommand ItemCommand} event of {@link TDataGrid} controls.
*
* The {@link getItem Item} property indicates the datagrid item related with the event.
* The {@link getCommandSource CommandSource} refers to the control that originally
* raises the Command event.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridCommandEventParameter extends TCommandEventParameter
{
/**
* @var TDataGridItem the TDataGridItem control responsible for the event.
*/
private $_item=null;
/**
* @var TControl the control originally raises the <b>Command</b> event.
*/
private $_source=null;
/**
* Constructor.
* @param TDataGridItem datagrid item responsible for the event
* @param TControl original event sender
* @param TCommandEventParameter original event parameter
*/
public function __construct($item,$source,TCommandEventParameter $param)
{
$this->_item=$item;
$this->_source=$source;
parent::__construct($param->getCommandName(),$param->getCommandParameter());
}
/**
* @return TDataGridItem the TDataGridItem control responsible for the event.
*/
public function getItem()
{
return $this->_item;
}
/**
* @return TControl the control originally raises the <b>Command</b> event.
*/
public function getCommandSource()
{
return $this->_source;
}
}
/**
* TDataGridSortCommandEventParameter class
*
* TDataGridSortCommandEventParameter encapsulates the parameter data for
* {@link TDataGrid::onSortCommand SortCommand} event of {@link TDataGrid} controls.
*
* The {@link getCommandSource CommandSource} property refers to the control
* that originally raises the Command event, while {@link getSortExpression SortExpression}
* gives the sort expression carried with the sort command.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridSortCommandEventParameter extends TEventParameter
{
/**
* @var string sort expression
*/
private $_sortExpression='';
/**
* @var TControl original event sender
*/
private $_source=null;
/**
* Constructor.
* @param TControl the control originally raises the <b>Command</b> event.
* @param TDataGridCommandEventParameter command event parameter
*/
public function __construct($source,TDataGridCommandEventParameter $param)
{
$this->_source=$source;
$this->_sortExpression=$param->getCommandParameter();
}
/**
* @return TControl the control originally raises the <b>Command</b> event.
*/
public function getCommandSource()
{
return $this->_source;
}
/**
* @return string sort expression
*/
public function getSortExpression()
{
return $this->_sortExpression;
}
}
/**
* TDataGridPageChangedEventParameter class
*
* TDataGridPageChangedEventParameter encapsulates the parameter data for
* {@link TDataGrid::onPageIndexChanged PageIndexChanged} event of {@link TDataGrid} controls.
*
* The {@link getCommandSource CommandSource} property refers to the control
* that originally raises the Command event, while {@link getNewPageIndex NewPageIndex}
* returns the new page index carried with the page command.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridPageChangedEventParameter extends TEventParameter
{
/**
* @var integer new page index
*/
private $_newIndex;
/**
* @var TControl original event sender
*/
private $_source=null;
/**
* Constructor.
* @param TControl the control originally raises the <b>Command</b> event.
* @param integer new page index
*/
public function __construct($source,$newPageIndex)
{
$this->_source=$source;
$this->_newIndex=$newPageIndex;
}
/**
* @return TControl the control originally raises the <b>Command</b> event.
*/
public function getCommandSource()
{
return $this->_source;
}
/**
* @return integer new page index
*/
public function getNewPageIndex()
{
return $this->_newIndex;
}
}
/**
* TDataGridItem class
*
* A TDataGridItem control represents an item in the {@link TDataGrid} control,
* such as heading section, footer section, or a data item.
* The index and data value of the item can be accessed via {@link getItemIndex ItemIndex}>
* and {@link getDataItem DataItem} properties, respectively. The type of the item
* is given by {@link getItemType ItemType} property. Property {@link getDataSourceIndex DataSourceIndex}
* gives the index of the item from the bound data source.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridItem extends TTableRow implements INamingContainer
{
/**
* @var integer index of the data item in the Items collection of datagrid
*/
private $_itemIndex='';
/**
* @var integer index of the item from the bound data source
*/
private $_dataSourceIndex=0;
/**
* type of the TDataGridItem
* @var string
*/
private $_itemType='';
/**
* value of the data item
* @var mixed
*/
private $_dataItem=null;
/**
* Constructor.
* @param integer zero-based index of the item in the item collection of datagrid
* @param string item type, can be 'Header','Footer','Item','AlternatingItem','SelectedItem','EditItem','Separator','Pager'.
*/
public function __construct($itemIndex,$dataSourceIndex,$itemType)
{
$this->_itemIndex=$itemIndex;
$this->_dataSourceIndex=$dataSourceIndex;
$this->setItemType($itemType);
if($itemType===TDataGrid::IT_HEADER)
$this->setTableSection('Header');
else if($itemType===TDataGrid::IT_FOOTER)
$this->setTableSection('Footer');
}
/**
* @return string item type.
*/
public function getItemType()
{
return $this->_itemType;
}
/**
* @param string item type, can be 'Header','Footer','Item','AlternatingItem','SelectedItem','EditItem','Separator','Pager'
*/
public function setItemType($value)
{
$this->_itemType=$value;
}
/**
* @return integer zero-based index of the item in the item collection of datagrid
*/
public function getItemIndex()
{
return $this->_itemIndex;
}
/**
* @return integer the index of the datagrid item from the bound data source
*/
public function getDataSourceIndex()
{
return $this->_dataSourceIndex;
}
/**
* @return mixed data associated with the item
*/
public function getDataItem()
{
return $this->_dataItem;
}
/**
* @param mixed data to be associated with the item
*/
public function setDataItem($value)
{
$this->_dataItem=$value;
}
/**
* This method overrides parent's implementation by wrapping event parameter
* for <b>OnCommand</b> event with item information.
* @param TControl the sender of the event
* @param TEventParameter event parameter
* @return boolean whether the event bubbling should stop here.
*/
public function bubbleEvent($sender,$param)
{
if($param instanceof TCommandEventParameter)
{
$this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
return true;
}
else
return false;
}
}
/**
* TDataGridPager class.
*
* TDataGridPager represents a datagrid pager.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridPager extends TPanel implements INamingContainer
{
private $_dataGrid;
/**
* Constructor.
* @param TDataGrid datagrid object
*/
public function __construct($dataGrid)
{
$this->_dataGrid=$dataGrid;
}
/**
* This method overrides parent's implementation by wrapping event parameter
* for <b>OnCommand</b> event with item information.
* @param TControl the sender of the event
* @param TEventParameter event parameter
* @return boolean whether the event bubbling should stop here.
*/
public function bubbleEvent($sender,$param)
{
if($param instanceof TCommandEventParameter)
{
$this->raiseBubbleEvent($this,new TDataGridCommandEventParameter($this,$sender,$param));
return true;
}
else
return false;
}
/**
* @return TDataGrid the datagrid owning this pager
*/
public function getDataGrid()
{
return $this->_dataGrid;
}
/**
* @return string item type.
*/
public function getItemType()
{
return TDataGrid::IT_PAGER;
}
}
/**
* TDataGridItemCollection class.
*
* TDataGridItemCollection represents a collection of data grid items.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridItemCollection extends TList
{
/**
* Inserts an item at the specified position.
* This overrides the parent implementation by inserting only TDataGridItem.
* @param integer the speicified position.
* @param mixed new item
* @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridItem.
*/
public function insertAt($index,$item)
{
if($item instanceof TDataGridItem)
parent::insertAt($index,$item);
else
throw new TInvalidDataTypeException('datagriditemcollection_datagriditem_required');
}
}
/**
* TDataGridColumnCollection class.
*
* TDataGridColumnCollection represents a collection of data grid columns.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridColumnCollection extends TList
{
/**
* the control that owns this collection.
* @var TControl
*/
private $_o;
/**
* Constructor.
* @param TDataGrid the control that owns this collection.
*/
public function __construct(TDataGrid $owner)
{
$this->_o=$owner;
}
/**
* @return TDataGrid the control that owns this collection.
*/
protected function getOwner()
{
return $this->_o;
}
/**
* Inserts an item at the specified position.
* This overrides the parent implementation by inserting only TDataGridColumn.
* @param integer the speicified position.
* @param mixed new item
* @throws TInvalidDataTypeException if the item to be inserted is not a TDataGridColumn.
*/
public function insertAt($index,$item)
{
if($item instanceof TDataGridColumn)
{
$item->setOwner($this->_o);
parent::insertAt($index,$item);
}
else
throw new TInvalidDataTypeException('datagridcolumncollection_datagridcolumn_required');
}
}
/**
* TDataGridPagerStyle class.
*
* TDataGridPagerStyle specifies the styles available for a datagrid pager.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Revision: $ $Date: $
* @package System.Web.UI.WebControls
* @since 3.0
*/
class TDataGridPagerStyle extends TPanelStyle
{
private $_mode=null;
private $_nextText=null;
private $_prevText=null;
private $_buttonCount=null;
private $_position=null;
private $_visible=null;
private $_buttonType=null;
/**
* @return string pager mode. Defaults to 'NextPrev'.
*/
public function getMode()
{
return $this->_mode===null?'NextPrev':$this->_mode;
}
/**
* @param string pager mode. Valid values include 'NextPrev' and 'Numeric'.
*/
public function setMode($value)
{
$this->_mode=TPropertyValue::ensureEnum($value,'NextPrev','Numeric');
}
/**
* @return string the type of command button. Defaults to LinkButton.
*/
public function getButtonType()
{
return $this->_buttonType===null?'LinkButton':$this->_buttonType;
}
/**
* @param string the type of command button, LinkButton or PushButton
*/
public function setButtonType($value)
{
$this->_buttonType=TPropertyValue::ensureEnum($value,'LinkButton','PushButton');
}
/**
* @return string text for the next page button. Defaults to '>'.
*/
public function getNextPageText()
{
return $this->_nextText===null?'>':$this->_nextText;
}
/**
* @param string text for the next page button.
*/
public function setNextPageText($value)
{
$this->_nextText=$value;
}
/**
* @return string text for the previous page button. Defaults to '<'.
*/
public function getPrevPageText()
{
return $this->_prevText===null?'<':$this->_prevText;
}
/**
* @param string text for the next page button.
*/
public function setPrevPageText($value)
{
$this->_prevText=$value;
}
/**
* @return integer maximum number of pager buttons to be displayed. Defaults to 10.
*/
public function getPageButtonCount()
{
return $this->_buttonCount===null?10:$this->_buttonCount;
}
/**
* @param integer maximum number of pager buttons to be displayed
* @throws TInvalidDataValueException if the value is less than 1.
*/
public function setPageButtonCount($value)
{
if(($value=TPropertyValue::ensureInteger($value))<1)
throw new TInvalidDataValueException('datagridpagerstyle_pagebuttoncount_invalid');
$this->_buttonCount=$value;
}
/**
* @return string where the pager is to be displayed. Defaults to 'Bottom'.
*/
public function getPosition()
{
return $this->_position===null?'Bottom':$this->_position;
}
/**
* @param string where the pager is to be displayed. Valid values include 'Bottom', 'Top', 'TopAndBottom'
*/
public function setPosition($value)
{
$this->_position=TPropertyValue::ensureEnum($value,'Bottom','Top','TopAndBottom');
}
/**
* @return boolean whether the pager is visible. Defaults to true.
*/
public function getVisible()
{
return $this->_visible===null?true:$this->_visible;
}
/**
* @param boolean whether the pager is visible.
*/
public function setVisible($value)
{
$this->_visible=TPropertyValue::ensureBoolean($value);
}
/**
* Resets the style to the original empty state.
*/
public function reset()
{
parent::reset();
$this->_visible=null;
$this->_position=null;
$this->_buttonCount=null;
$this->_prevText=null;
$this->_nextText=null;
$this->_mode=null;
$this->_buttonType=null;
}
/**
* Copies the fields in a new style to this style.
* If a style field is set in the new style, the corresponding field
* in this style will be overwritten.
* @param TStyle the new style
*/
public function copyFrom($style)
{
parent::copyFrom($style);
if($style instanceof TDataGridPagerStyle)
{
if($style->_visible!==null)
$this->_visible=$style->_visible;
if($style->_position!==null)
$this->_position=$style->_position;
if($style->_buttonCount!==null)
$this->_buttonCount=$style->_buttonCount;
if($style->_prevText!==null)
$this->_prevText=$style->_prevText;
if($style->_nextText!==null)
$this->_nextText=$style->_nextText;
if($style->_mode!==null)
$this->_mode=$style->_mode;
if($style->_buttonType!==null)
$this->_buttonType=$style->_buttonType;
}
}
/**
* Merges the style with a new one.
* If a style field is not set in this style, it will be overwritten by
* the new one.
* @param TStyle the new style
*/
public function mergeWith($style)
{
parent::mergeWith($style);
if($style instanceof TDataGridPagerStyle)
{
if($this->_visible===null)
$this->_visible=$style->_visible;
if($this->_position===null)
$this->_position=$style->_position;
if($this->_buttonCount===null)
$this->_buttonCount=$style->_buttonCount;
if($this->_prevText===null)
$this->_prevText=$style->_prevText;
if($this->_nextText===null)
$this->_nextText=$style->_nextText;
if($this->_mode===null)
$this->_mode=$style->_mode;
if($this->_buttonType===null)
$this->_buttonType=$style->_buttonType;
}
}
}
?>
|