Debian Codegraph @

dojox/grid/enhanced/plugins/exporter/TableWriter.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare",
3 "dojo/_base/array",
4 "dojo/dom-geometry",
5 "./_ExportWriter",
6 "../Exporter"
7 ], function(declare, array, domGeometry, _ExportWriter, Exporter){
8
9 Exporter.registerWriter("table", "dojox.grid.enhanced.plugins.exporter.TableWriter");
10
11 return declare("dojox.grid.enhanced.plugins.exporter.TableWriter", _ExportWriter, {
12 // summary:
13 // Export grid to HTML table format. Primarily used by Printer plugin.
14 constructor: function(/* object? */writerArgs){
15 // summary:
16 // The generated table only defines the col/rowspan, height and width of
17 // all the cells in the style attribute, no other attributes
18 // (like border, cellspacing, etc.) are used.
19 // Users can define these attributes in the writerArgs object, like:
20 // {table:"border='border'",thead:"cellspacing='3'"}
21 this._viewTables = [];
22 this._tableAttrs = writerArgs || {};
23 },
24
25 _getTableAttrs: function(/* string */tagName){
26 // summary:
27 // Get html attribute string for the given kind of tag.
28 // tags:
29 // private
30 // tagName: string
31 // An html tag name
32 // returns:
33 // The well formatted attributes for the given html table.tag
34 var attrs = this._tableAttrs[tagName] || '';
35 //To ensure the attribute list starts with a space
36 if(attrs && attrs[0] != ' '){
37 attrs = ' ' + attrs;
38 }
39 return attrs; //String
40 },
41
42 _getRowClass: function(/* object */arg_obj){
43 // summary:
44 // Get CSS class string for a row
45 // tags:
46 // private
47 return arg_obj.isHeader ? " grid_header" : [//String
48 " grid_row grid_row_",
49 arg_obj.rowIdx + 1,
50 arg_obj.rowIdx % 2 ? " grid_even_row" : " grid_odd_row"
51 ].join('');
52 },
53
54 _getColumnClass: function(/* object */arg_obj){
55 // summary:
56 // Get CSS class string for a column
57 // tags:
58 // private
59 var col_idx = arg_obj.cell.index + arg_obj.colOffset + 1;
60 return [" grid_column grid_column_", col_idx,//String
61 col_idx % 2 ? " grid_odd_column" : " grid_even_column"].join('');
62 },
63
64 beforeView: function(/* object */arg_obj){
65 // summary:
66 // Overrided from _ExportWriter
67 var viewIdx = arg_obj.viewIdx,
68 table = this._viewTables[viewIdx],
69 height, width = domGeometry.getMarginBox(arg_obj.view.contentNode).w;
70 if(!table){
71 var left = 0;
72 for(var i = 0; i < viewIdx; ++i){
73 left += this._viewTables[i]._width;
74 }
75 table = this._viewTables[viewIdx] = ['<div class="grid_view" style="position: absolute; top: 0; ',
76 domGeometry.isBodyLtr() ? 'left' : 'right', ':', left,
77 'px;">'];
78 }
79 table._width = width;
80 if(arg_obj.isHeader){
81 height = domGeometry.getContentBox(arg_obj.view.headerContentNode).h;
82 }else{
83 var rowNode = arg_obj.grid.getRowNode(arg_obj.rowIdx);
84 if(rowNode){
85 height = domGeometry.getContentBox(rowNode).h;
86 }else{
87 //This row has not been loaded from store, so we should estimate it's height.
88 height = arg_obj.grid.scroller.averageRowHeight;
89 }
90 }
91 table.push('<table class="', this._getRowClass(arg_obj),
92 '" style="table-layout:fixed; height:', height, 'px; width:', width, 'px;" ',
93 'border="0" cellspacing="0" cellpadding="0" ',
94 this._getTableAttrs("table"),
95 '><tbody ', this._getTableAttrs('tbody'), '>');
96 return true; //Boolean
97 },
98
99 afterView: function(/* object */arg_obj){
100 // summary:
101 // Overrided from _ExportWriter
102 this._viewTables[arg_obj.viewIdx].push('</tbody></table>');
103 },
104
105 beforeSubrow: function(/* object */arg_obj){
106 // summary:
107 // Overrided from _ExportWriter
108 this._viewTables[arg_obj.viewIdx].push('<tr', this._getTableAttrs('tr'), '>');
109 return true; //Boolean
110 },
111
112 afterSubrow: function(/* object */arg_obj){
113 // summary:
114 // Overrided from _ExportWriter
115 this._viewTables[arg_obj.viewIdx].push('</tr>');
116 },
117
118 handleCell: function(/* object */arg_obj){
119 // summary:
120 // Overrided from _ExportWriter
121 var cell = arg_obj.cell;
122 if(cell.hidden || array.indexOf(arg_obj.spCols, cell.index) >= 0){
123 //We are not interested in indirect selectors and row indexes.
124 return;
125 }
126 var cellTagName = arg_obj.isHeader ? 'th' : 'td',
127 attrs = [cell.colSpan ? ' colspan="' + cell.colSpan + '"' : '',
128 cell.rowSpan ? ' rowspan="' + cell.rowSpan + '"' : '',
129 ' style="width: ', domGeometry.getContentBox(cell.getHeaderNode()).w, 'px;"',
130 this._getTableAttrs(cellTagName),
131 ' class="', this._getColumnClass(arg_obj), '"'].join(''),
132 table = this._viewTables[arg_obj.viewIdx];
133 table.push('<', cellTagName, attrs, '>');
134 if(arg_obj.isHeader){
135 table.push(cell.name || cell.field);
136 } else{
137 table.push(this._getExportDataForCell(arg_obj.rowIdx, arg_obj.row, cell, arg_obj.grid));
138 }
139 table.push('</', cellTagName, '>');
140 },
141
142 afterContent: function(){
143 // summary:
144 // Overrided from _ExportWriter
145 array.forEach(this._viewTables, function(table){
146 table.push('</div>');
147 });
148 },
149
150 toString: function(){
151 // summary:
152 // Overrided from _ExportWriter
153 var viewsHTML = array.map(this._viewTables, function(table){ //String
154 return table.join('');
155 }).join('');
156 return ['<div style="position: relative;">', viewsHTML, '</div>'].join('');
157 }
158 });
159 });