1: <?php
2: require_once('../qcubed.inc.php');
3:
4: class ComplexColumn extends QHtmlTableIndexedColumn {
5: public function RenderHeaderCell() {
6: if ($this->objParentTable->CurrentHeaderRowIndex == 0 &&
7: $this->Index > 1) {
8: return null;
9: } else {
10: return parent::RenderHeaderCell ();
11: }
12: }
13:
14: public function FetchHeaderCellValue() {
15: if ($this->objParentTable->CurrentHeaderRowIndex == 0 &&
16: $this->Index == 1) {
17: return 'Year';
18: }
19: return parent::FetchHeaderCellValue();
20: }
21:
22:
23: public function GetHeaderCellParams() {
24: $a = parent::GetHeaderCellParams();
25: if ($this->Index == 0) {
26:
27: $a['style'] = 'background-color: white';
28: }
29: if ($this->ParentTable->CurrentHeaderRowIndex == 0) {
30: if ($this->Index == 1) {
31: $a['colspan'] = 3;
32: }
33: }
34: return $a;
35: }
36: }
37:
38:
39: class ExampleForm extends QForm {
40:
41:
42: protected $tblPersons;
43:
44:
45: protected $tblReport;
46:
47:
48: protected $tblComplex;
49:
50: protected function Form_Create() {
51:
52: $this->tblPersons = new QHtmlTable($this);
53: $this->tblPersons->CssClass = 'simple_table';
54: $this->tblPersons->RowCssClass = 'odd_row';
55: $this->tblPersons->AlternateRowCssClass = 'even_row';
56: $this->tblPersons->HeaderRowCssClass = 'header_row';
57:
58:
59:
60: $objColumn = new QHtmlTableCallableColumn('Full Name', [$this, 'getFullName']);
61: $this->tblPersons->AddColumn($objColumn);
62:
63:
64:
65: $this->tblPersons->CreatePropertyColumn('First Name', 'FirstName');
66:
67:
68: $this->tblPersons->CreateNodeColumn('Last Name', QQN::Person()->LastName);
69:
70:
71:
72:
73:
74:
75:
76: $this->tblPersons->SetDataBinder('tblPersons_Bind');
77:
78: $this->tblReport = new QHtmlTable($this);
79: $this->tblReport->CssClass = 'simple_table';
80: $this->tblReport->RowCssClass = 'odd_row';
81: $this->tblReport->AlternateRowCssClass = 'even_row';
82: $this->tblReport->HeaderRowCssClass = 'header_row';
83:
84:
85: $this->tblReport->CreateIndexedColumn("Year", 0);
86: $this->tblReport->CreateIndexedColumn("Model", 1);
87:
88: $this->tblReport->CreateIndexedColumn();
89: $this->tblReport->CreateIndexedColumn();
90:
91: $this->tblReport->CreateIndexedColumn("Count", "#count");
92:
93: $this->tblReport->SetDataBinder('tblReport_Bind');
94:
95: $this->tblComplex = new QHtmlTable($this);
96: $this->tblComplex->CssClass = 'simple_table';
97: $this->tblComplex->RowCssClass = 'odd_row';
98: $this->tblComplex->AlternateRowCssClass = 'even_row';
99: $this->tblComplex->HeaderRowCssClass = 'header_row';
100:
101:
102: $col = $this->tblComplex->AddColumn (new ComplexColumn("", "Name"));
103: $col->RenderAsHeader = true;
104: $this->tblComplex->AddColumn (new ComplexColumn("2000", 1));
105: $this->tblComplex->AddColumn (new ComplexColumn("2001", 2));
106: $this->tblComplex->AddColumn (new ComplexColumn("2002", 3));
107: $this->tblComplex->HeaderRowCount = 2;
108:
109: $this->tblComplex->SetDataBinder('tblComplex_Bind');
110: }
111:
112: protected function tblPersons_Bind() {
113:
114: $this->tblPersons->DataSource = Person::LoadAll();
115: }
116:
117: public function getFullName($item) {
118: return 'Full Name is "' . $item->FirstName . ' ' . $item->LastName . '"';
119: }
120:
121: protected function tblReport_Bind() {
122:
123: $csv = '1997,Ford,E350,"ac, abs, moon",3000.00
124: 1999,Chevy,"Venture ""Extended Edition""","",4900.00
125: 1999,Chevy,"Venture ""Extended Edition, Very Large""","",5000.00
126: 1996,Jeep,Grand Cherokee,"MUST SELL!';
127: $data = str_getcsv($csv, "\n");
128: foreach ($data as &$row) {
129: $row = str_getcsv($row, ",");
130: $row["#count"] = count($row);
131: }
132: $this->tblReport->DataSource = $data;
133: }
134: protected function tblComplex_Bind() {
135: $a[] = array ('Name' => 'Income', 1=>1000, 2=>2000, 3=>1500);
136: $a[] = array ('Name' => 'Expense', 1=>500, 2=>700, 3=>2100);
137: $a[] = array ('Name' => 'Net', 1=>1000-500, 2=>2000-700, 3=>1500-2100);
138:
139: $this->tblComplex->DataSource = $a;
140: }
141:
142: }
143:
144: ExampleForm::Run('ExampleForm');
145: ?>