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
24 if (!Rico.isIE) document.getElementById('owc').disabled=true;
\r
27 function ExportGridClient(ExportType) {
\r
28 ex1.printVisible(ExportType);
\r
31 function ExportGridServer(ExportType) {
\r
33 location.href+='&fmt='+ExportType;
\r
35 window.open(location.href+'&fmt='+ExportType);
\r
40 <style type="text/css">
\r
44 font-weight:bold !important;
\r
49 font-weight:bold !important;
\r
54 font-weight:bold !important;
\r
66 <table id='explanation' border='0' cellpadding='0' cellspacing='5' style='clear:both'><tr valign='top'><td>
\r
68 <script type='text/javascript'>
\r
69 document.write(Rico.Lib+' '+Rico.LibVersion);
\r
72 <p><strong>Rico: SimpleGrid</strong></p>
\r
73 <p>Rico's SimpleGrid is an unbuffered grid - all data exists in the DOM.
\r
74 It shares many of the same characteristics as Rico's better known LiveGrid.
\r
75 SimpleGrids have resizable columns, frozen columns on the left, and can use the
\r
76 same CSS styling as LiveGrids. Sorting and filtering can also be enabled
\r
77 at the developer's discretion. Unlike LiveGrids, each cell in a SimpleGrid
\r
78 can be formatted individually.
\r
89 <button onclick="ExportGridClient('plain')">Export from client<br>to HTML Table</button>
\r
90 <button onclick="ExportGridClient('owc')" id="owc">Export from client<br>to OWC spreadsheet</button>
\r
91 <button onclick="ExportGridServer('xl')">Export from server<br>to Excel</button>
\r
92 <button onclick="ExportGridServer('csv')">Export from server<br>to CSV</button>
\r
98 echo "<p>ERROR opening database!";
\r
100 $grid=new SimpleGrid();
\r
102 $fmt=isset($_GET["fmt"]) ? $_GET["fmt"] : "";
\r
103 switch (strtolower($fmt)) {
\r
105 $grid->RenderExcel("rico.xls");
\r
108 $grid->RenderDelimited("rico.csv", ",", "");
\r
111 $grid->Render("ex1", 0); // output html
\r
118 function FillGrid() {
\r
120 $subtotals=array();
\r
121 $grandtotals=array();
\r
122 for ($i=0; $i<=1; $i++) {
\r
123 $grandtotals[$i]=0;
\r
126 $grid->AddHeadingRow(true);
\r
127 $grid->AddCell("Product");
\r
128 $grid->AddCell("Gross Sales");
\r
129 $grid->AddCell("Discounts");
\r
130 $grid->AddCell("Net Sales");
\r
131 $grid->AddCell("Avg Discount");
\r
132 $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
133 $rsMain=$oDB->RunQuery($sqltext);
\r
134 while ($oDB->db->FetchRow($rsMain,$row)) {
\r
137 $Discounts=$row[3];
\r
138 if ($category != $lastCategory) {
\r
139 if (!empty($lastCategory)) {
\r
140 AddRow("Subtotal", $subtotals[0], $subtotals[1]);
\r
141 $grid->SetRowAttr("class", "Subtotal");
\r
143 $grid->AddDataRow();
\r
144 $grid->SetRowAttr("class", "CatHead");
\r
145 $grid->AddCell($category);
\r
146 $grid->AddCell("");
\r
147 $grid->AddCell("");
\r
148 $grid->AddCell("");
\r
149 $grid->AddCell("");
\r
150 for ($i=0; $i<=1; $i++) {
\r
153 $lastCategory=$category;
\r
155 $subtotals[0]+=$Gross;
\r
156 $grandtotals[0]+=$Gross;
\r
157 $subtotals[1]+=$Discounts;
\r
158 $grandtotals[1]+=$Discounts;
\r
159 AddRow($row[1], $Gross, $Discounts);
\r
161 $oDB->rsClose($rsMain);
\r
162 if (!empty($lastCategory)) {
\r
163 AddRow("Subtotal", $subtotals[0], $subtotals[1]);
\r
164 $grid->SetRowAttr("class", "Subtotal");
\r
166 AddRow("Grand Total", $grandtotals[0], $grandtotals[1]);
\r
167 $grid->SetRowAttr("class", "GrandTotal");
\r
170 function AddRow($ProductName, $Gross, $Discounts) {
\r
172 $grid->AddDataRow();
\r
173 $grid->AddCell(htmlspecialchars(utf8_encode($ProductName), ENT_COMPAT, 'UTF-8'));
\r
174 $grid->AddCell("$".number_format($Gross));
\r
175 $grid->AddCell("$".number_format($Discounts));
\r
176 $grid->AddCell("$".number_format($Gross-$Discounts));
\r
177 $grid->AddCell(round($Discounts / $Gross * 100.0)."%");
\r