3 header('Content-type: text/html; charset=utf-8');
\r
5 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
\r
8 <title>Rico SimpleGrid-Example 1</title>
\r
11 require "dbConnect.php";
\r
12 require "LoadRicoClient.php";
\r
13 require "../../plugins/php/SimpleGrid.php";
\r
15 <link href="../demo.css" type="text/css" rel="stylesheet" />
\r
17 <script type='text/javascript'>
\r
19 Rico.onLoad( function() {
\r
21 columnSpecs : [{width:200},'specQty','specQty','specQty','specQty']
\r
23 ex1=new Rico.SimpleGrid ('ex1', opts);
\r
26 function ExportGridClient(ExportType) {
\r
27 ex1.printVisible(ExportType);
\r
30 function ExportGridServer(ExportType) {
\r
32 location.href+='&fmt='+ExportType;
\r
34 window.open(location.href+'&fmt='+ExportType);
\r
39 <style type="text/css">
\r
43 font-weight:bold !important;
\r
48 font-weight:bold !important;
\r
53 font-weight:bold !important;
\r
65 <table id='explanation' border='0' cellpadding='0' cellspacing='5' style='clear:both'><tr valign='top'><td>
\r
67 <script type='text/javascript'>
\r
68 document.write(Rico.Lib+' '+Rico.LibVersion);
\r
71 <p><strong>Rico: SimpleGrid</strong></p>
\r
72 <p>Rico's SimpleGrid is an unbuffered grid - all data exists in the DOM.
\r
73 It shares many of the same characteristics as Rico's better known LiveGrid.
\r
74 SimpleGrids have resizable columns, frozen columns on the left, and can use the
\r
75 same CSS styling as LiveGrids. Sorting and filtering can also be enabled
\r
76 at the developer's discretion. Unlike LiveGrids, each cell in a SimpleGrid
\r
77 can be formatted individually.
\r
88 <button onclick="ExportGridClient('plain')">Export from client<br>to HTML Table</button>
\r
89 <button onclick="ExportGridServer('xl')">Export from server<br>to Excel</button>
\r
90 <button onclick="ExportGridServer('csv')">Export from server<br>to CSV</button>
\r
96 echo "<p>ERROR opening database!";
\r
98 $grid=new SimpleGrid();
\r
100 $fmt=isset($_GET["fmt"]) ? $_GET["fmt"] : "";
\r
101 switch (strtolower($fmt)) {
\r
103 $grid->RenderExcel("rico.xls");
\r
106 $grid->RenderDelimited("rico.csv", ",", "");
\r
109 $grid->Render("ex1", 0); // output html
\r
116 function FillGrid() {
\r
118 $subtotals=array();
\r
119 $grandtotals=array();
\r
120 for ($i=0; $i<=1; $i++) {
\r
121 $grandtotals[$i]=0;
\r
124 $grid->AddHeadingRow(true);
\r
125 $grid->AddCell("Product");
\r
126 $grid->AddCell("Gross Sales");
\r
127 $grid->AddCell("Discounts");
\r
128 $grid->AddCell("Net Sales");
\r
129 $grid->AddCell("Avg Discount");
\r
130 $sqltext="select CategoryName,ProductName, SUM(od.UnitPrice*Quantity) as GrossSales, SUM(od.UnitPrice*Quantity*Discount) as Discounts from (Order_Details od inner join Products p on p.ProductID=od.ProductID) inner join Categories c on p.CategoryID=c.CategoryID group by CategoryName,ProductName order by CategoryName,ProductName";
\r
131 $rsMain=$oDB->RunQuery($sqltext);
\r
132 while ($oDB->db->FetchRow($rsMain,$row)) {
\r
135 $Discounts=$row[3];
\r
136 if ($category != $lastCategory) {
\r
137 if (!empty($lastCategory)) {
\r
138 AddRow("Subtotal", $subtotals[0], $subtotals[1]);
\r
139 $grid->SetRowAttr("class", "Subtotal");
\r
141 $grid->AddDataRow();
\r
142 $grid->SetRowAttr("class", "CatHead");
\r
143 $grid->AddCell($category);
\r
144 $grid->AddCell("");
\r
145 $grid->AddCell("");
\r
146 $grid->AddCell("");
\r
147 $grid->AddCell("");
\r
148 for ($i=0; $i<=1; $i++) {
\r
151 $lastCategory=$category;
\r
153 $subtotals[0]+=$Gross;
\r
154 $grandtotals[0]+=$Gross;
\r
155 $subtotals[1]+=$Discounts;
\r
156 $grandtotals[1]+=$Discounts;
\r
157 AddRow($row[1], $Gross, $Discounts);
\r
159 $oDB->rsClose($rsMain);
\r
160 if (!empty($lastCategory)) {
\r
161 AddRow("Subtotal", $subtotals[0], $subtotals[1]);
\r
162 $grid->SetRowAttr("class", "Subtotal");
\r
164 AddRow("Grand Total", $grandtotals[0], $grandtotals[1]);
\r
165 $grid->SetRowAttr("class", "GrandTotal");
\r
168 function AddRow($ProductName, $Gross, $Discounts) {
\r
170 $grid->AddDataRow();
\r
171 $grid->AddCell(htmlspecialchars(utf8_encode($ProductName), ENT_COMPAT, 'UTF-8'));
\r
172 $grid->AddCell("$".number_format($Gross));
\r
173 $grid->AddCell("$".number_format($Discounts));
\r
174 $grid->AddCell("$".number_format($Gross-$Discounts));
\r
175 $grid->AddCell(round($Discounts / $Gross * 100.0)."%");
\r