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
18 Rico.loadModule('SimpleGrid');
\r
21 Rico.onLoad( function() {
\r
23 columnSpecs : [{width:200},'specQty','specQty','specQty','specQty']
\r
25 ex1=new Rico.SimpleGrid ('ex1', opts);
\r
26 if (!Rico.isIE) document.getElementById('owc').disabled=true;
\r
29 function ExportGridClient(ExportType) {
\r
30 ex1.printVisible(ExportType);
\r
33 function ExportGridServer(ExportType) {
\r
35 location.href+='&fmt='+ExportType;
\r
37 window.open(location.href+'&fmt='+ExportType);
\r
42 <style type="text/css">
\r
46 font-weight:bold !important;
\r
51 font-weight:bold !important;
\r
56 font-weight:bold !important;
\r
68 <table id='explanation' border='0' cellpadding='0' cellspacing='5' style='clear:both'><tr valign='top'><td>
\r
70 <script type='text/javascript'>
\r
71 document.write(Rico.Lib+' '+Rico.LibVersion);
\r
74 <p><strong>Rico: SimpleGrid</strong></p>
\r
75 <p>Rico's SimpleGrid is an unbuffered grid - all data exists in the DOM.
\r
76 It shares many of the same characteristics as Rico's better known LiveGrid.
\r
77 SimpleGrids have resizable columns, frozen columns on the left, and can use the
\r
78 same CSS styling as LiveGrids. Sorting and filtering can also be enabled
\r
79 at the developer's discretion. Unlike LiveGrids, each cell in a SimpleGrid
\r
80 can be formatted individually.
\r
83 <script type="text/javascript"><!--
\r
84 google_ad_client = "pub-7218597156507462";
\r
85 /* 125x125, created 5/11/09 */
\r
86 google_ad_slot = "9298106441";
\r
87 google_ad_width = 125;
\r
88 google_ad_height = 125;
\r
91 <script type="text/javascript"
\r
92 src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
\r
99 <button onclick="ExportGridClient('plain')">Export from client<br>to HTML Table</button>
\r
100 <button onclick="ExportGridClient('owc')" id="owc">Export from client<br>to OWC spreadsheet</button>
\r
101 <button onclick="ExportGridServer('xl')">Export from server<br>to Excel</button>
\r
102 <button onclick="ExportGridServer('csv')">Export from server<br>to CSV</button>
\r
108 echo "<p>ERROR opening database!";
\r
110 $grid=new SimpleGrid();
\r
112 $fmt=isset($_GET["fmt"]) ? $_GET["fmt"] : "";
\r
113 switch (strtolower($fmt)) {
\r
115 $grid->RenderExcel("rico.xls");
\r
118 $grid->RenderDelimited("rico.csv", ",", "");
\r
121 $grid->Render("ex1", 0); // output html
\r
128 function FillGrid() {
\r
130 $subtotals=array();
\r
131 $grandtotals=array();
\r
132 for ($i=0; $i<=1; $i++) {
\r
133 $grandtotals[$i]=0;
\r
136 $grid->AddHeadingRow(true);
\r
137 $grid->AddCell("Product");
\r
138 $grid->AddCell("Gross Sales");
\r
139 $grid->AddCell("Discounts");
\r
140 $grid->AddCell("Net Sales");
\r
141 $grid->AddCell("Avg Discount");
\r
142 $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
143 $rsMain=$oDB->RunQuery($sqltext);
\r
144 while ($oDB->db->FetchRow($rsMain,$row)) {
\r
147 $Discounts=$row[3];
\r
148 if ($category != $lastCategory) {
\r
149 if (!empty($lastCategory)) {
\r
150 AddRow("Subtotal", $subtotals[0], $subtotals[1]);
\r
151 $grid->SetRowAttr("class", "Subtotal");
\r
153 $grid->AddDataRow();
\r
154 $grid->SetRowAttr("class", "CatHead");
\r
155 $grid->AddCell($category);
\r
156 $grid->AddCell("");
\r
157 $grid->AddCell("");
\r
158 $grid->AddCell("");
\r
159 $grid->AddCell("");
\r
160 for ($i=0; $i<=1; $i++) {
\r
163 $lastCategory=$category;
\r
165 $subtotals[0]+=$Gross;
\r
166 $grandtotals[0]+=$Gross;
\r
167 $subtotals[1]+=$Discounts;
\r
168 $grandtotals[1]+=$Discounts;
\r
169 AddRow($row[1], $Gross, $Discounts);
\r
171 $oDB->rsClose($rsMain);
\r
172 if (!empty($lastCategory)) {
\r
173 AddRow("Subtotal", $subtotals[0], $subtotals[1]);
\r
174 $grid->SetRowAttr("class", "Subtotal");
\r
176 AddRow("Grand Total", $grandtotals[0], $grandtotals[1]);
\r
177 $grid->SetRowAttr("class", "GrandTotal");
\r
180 function AddRow($ProductName, $Gross, $Discounts) {
\r
182 $grid->AddDataRow();
\r
183 $grid->AddCell(htmlspecialchars(utf8_encode($ProductName), ENT_COMPAT, 'UTF-8'));
\r
184 $grid->AddCell("$".number_format($Gross));
\r
185 $grid->AddCell("$".number_format($Discounts));
\r
186 $grid->AddCell("$".number_format($Gross-$Discounts));
\r
187 $grid->AddCell(round($Discounts / $Gross * 100.0)."%");
\r