Debian Codegraph @

dojox/grid/tests/enhanced/test_enhanced_grid_print_export.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <title>Test Print/Export plugins of dojox.grid.EnhancedGrid</title>
6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
7 <link rel=stylesheet href="support/common.css"/>
8 <style type="text/css">
9 body {
10 font-size: 0.9em;
11 font-family: Geneva, Arial, Helvetica, sans-serif;
12 padding: 0.5em;
13 }
14 .title {
15 text-align:center;
16 margin:1em;
17 }
18 #grid{
19 width: 95em;
20 height: 50em;
21 }
22 </style>
23 <script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="isDebug:true, parseOnLoad: true"></script>
24 <script type="text/javascript" src="../../../../dijit/tests/_testCommon.js"></script>
25 <script type="text/javascript">
26 dojo.require("dojo.parser");
27 dojo.require("dojo.data.ItemFileWriteStore");
28 dojo.require("dojox.grid.EnhancedGrid");
29 dojo.require("dojox.data.CsvStore");
30 dojo.require("dojox.grid.enhanced.plugins.exporter.CSVWriter");
31 dojo.require("dojox.grid.enhanced.plugins.Printer");
32
33 var layout = [//--------------------------------------------------------------------------5
34 {//first view
35 rows:
36 [
37 [
38 { field: "Genre", width: '10', rowSpan: 2},
39 { field: "Artist", width: '15'},
40 { field: "Year", width: '15'},
41 ],[
42 { field: "Album", colSpan: 2}
43 ]
44 ]
45 },
46 {//second view
47 rows:
48 [
49 [
50 { field: "Name", width: '20', rowSpan: 2},
51 { field: "Length", width: '20'},
52 { field: "Track"}
53 ],[
54 { field: "Composer", colSpan: 2},
55
56 ],[
57 { field: "Download Date"},
58 { field: "Last Played"},
59 { field: "Checked"}
60 ]
61 ]
62 }
63 ];
64 var plugins = {
65 printer: true
66 };
67 function exportCSV(){
68 dijit.byId("grid").exportGrid("csv", {
69 writerArgs: {
70 separator: dojo.byId('sep').value
71 }
72 }, function(str){
73 dojo.byId("csvResults").value = str;
74 });
75 }
76 function exportSelected(){
77 var s = dojo.byId('sep').value;
78 dojo.byId("csvResults").value = dijit.byId("grid").exportSelected("csv", {
79 separator: s
80 });
81 }
82 function exportTable(){
83 dijit.byId("grid").exportGrid("table", function(str){
84 dojo.byId("csvResults").value = str;
85 });
86 }
87 function printGrid(){
88 dijit.byId("grid").printGrid({
89 title: dojo.byId('print_title').value,
90 cssFiles: ["support/print_style1.css","support/print_style2.css"]
91 });
92 }
93 function printSelected(){
94 dijit.byId("grid").printSelected({
95 title: dojo.byId('print_title').value,
96 cssFiles: ["support/print_style1.css", "support/print_style2.css"]
97 });
98 }
99 function printPreview(){
100 var g = dijit.byId("grid");
101 g.exportToHTML({
102 title: dojo.byId('print_title').value,
103 cssFiles: ["support/print_style1.css", "support/print_style2.css"]
104 }, function(str){
105 var win = window.open();
106 win.document.open();
107 win.document.write(str);
108 g.normalizePrintedGrid(win.document);
109 win.document.close();
110 });
111 }
112 </script>
113 <script type="text/javascript" src="support/test_write_store_music.js"></script>
114 </head>
115 <body class="claro">
116 <h1 class="title">dojox.grid.EnhancedGrid - Print, Export</h1>
117 <div id="gridContainer">
118 <div id="grid" dojoType="dojox.grid.EnhancedGrid" store="test_store[0]" structure="layout" plugins="plugins"></div>
119 </div><br/>
120 <div>
121 <h2>Printer API</h2>
122 <input type='button' value='Print All' onclick='printGrid()' />
123 <input type='button' value='Print Selected' onclick='printSelected()' />
124 <input type='button' value='Print Preview' onclick='printPreview()' />
125 Use Title:<input id='print_title' type='text' value='Favorite Music' />
126 <br/>
127 <h4>Usage 1:</h4>
128 <div style="width:100%;">
129 <pre style="float:left;">someGrid.printGrid({
130 title: "A title: All Content",
131 cssFiles: ["cssfile1.css","cssfile2.css"],
132 writerArgs: {table:"border='border'"},
133 fetchArgs: {start: 0, count: 100}
134 });</pre>
135 <pre style="float:left;">someGrid.printSelected({
136 title: "A title: Only Selected",
137 cssFiles: ["cssfile1.css","cssfile2.css"],
138 writerArgs: {table:"border='border'"}
139 });</pre>
140 </div>
141 <p style="width:100%;clear:left;">
142 Generate an HTML string containing all the content in the grid and then print it.
143 </p>
144 <ul>
145 <li>A title, an array of CSS files and an associative array containing HTML tag attributes can be provided.</li>
146 <li><b>All three arguments are optional</b>
147 <li>The generated HTML page assigns predefined CSS classes for grid rows and columns, so the user can design styles for every rows,columns or even a single cell.</li>
148 </ul>
149 <h4>Usage 2:</h4>
150 <div>
151 <pre style="float:left;">someGrid.exportToHTML({
152 title: "Export All To HTML",
153 cssFiles: ["cssfile1.css","cssfile2.css"],
154 writerArgs: {table:"border='border'"},
155 fetchArgs: {start: 0, count: 100}
156 }, function(html){
157 /* do sth with the generated html page */
158 });</pre>
159 <pre style="float:left;">var html =
160 someGrid.exportSelectedToHTML({
161 title: "Export Selected Rows to HTML",
162 cssFiles: ["cssfile1.css","cssfile2.css"],
163 writerArgs: {table:"border='border'"}
164 });</pre>
165 </div>
166 <p style="width:100%;clear:left;">
167 Do not print, only generate html string. Users can use this to implement preview.
168 </p>
169 <hr/>
170 <h2>Exporter API</h2>
171 <input type='button' value='Export All to CSV' onclick='exportCSV()' />
172 <input type='button' value='Export Selected to CSV' onclick='exportSelected()' />
173 Separator is:<input id='sep' type='text' value=',' />
174 <input type='button' value='Export All to HTML Table' onclick='exportTable()' /><br/>
175 Results:<br />
176 <textarea rows="10" cols="100" id="csvResults"></textarea>
177 <h4>Usage:</h4>
178 <pre style="float:left;">someGrid.exportGrid("csv", {
179 writerArgs: {separator:":"},
180 fetchArgs: {start: 0, count: 100}
181 }, function(str){
182 /* do sth with str */
183 });</pre>
184 <pre style="float:left;">var str =
185 someGrid.exportSelected("csv", {
186 writerArgs: {separator:"###"}
187 });</pre>
188 <p style="width:100%;clear:left;">
189 Export grid content to a specified format.
190 </p>
191 <ul>
192 <li>The type argument is a supported format name, mandatory.</li>
193 <li>The writerArgs argument is a format-specific argument, optional.</li>
194 <li>If we are exporting everything, a callback function should be provided.</li>
195 <li>Actually, the printer is implemented using an HTML Table exporter</li>
196 </ul>
197 </div>
198 <p><strong>Note:</strong> To see the tundra theme, just append <b style="color:blue;">?theme=tundra</b> to the URL.</p>
199 </body>
200 </html>