| 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 |
|
| 13 |
|
| 14 |
constructor: function(writerArgs){ |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
this._viewTables = []; |
| 22 |
this._tableAttrs = writerArgs || {}; |
| 23 |
}, |
| 24 |
|
| 25 |
_getTableAttrs: function(tagName){ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
var attrs = this._tableAttrs[tagName] || ''; |
| 35 |
|
| 36 |
if(attrs && attrs[0] != ' '){ |
| 37 |
attrs = ' ' + attrs; |
| 38 |
} |
| 39 |
return attrs; |
| 40 |
}, |
| 41 |
|
| 42 |
_getRowClass: function(arg_obj){ |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
return arg_obj.isHeader ? " grid_header" : [ |
| 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(arg_obj){ |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
var col_idx = arg_obj.cell.index + arg_obj.colOffset + 1; |
| 60 |
return [" grid_column grid_column_", col_idx, |
| 61 |
col_idx % 2 ? " grid_odd_column" : " grid_even_column"].join(''); |
| 62 |
}, |
| 63 |
|
| 64 |
beforeView: function(arg_obj){ |
| 65 |
|
| 66 |
|
| 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 |
|
| 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; |
| 97 |
}, |
| 98 |
|
| 99 |
afterView: function(arg_obj){ |
| 100 |
|
| 101 |
|
| 102 |
this._viewTables[arg_obj.viewIdx].push('</tbody></table>'); |
| 103 |
}, |
| 104 |
|
| 105 |
beforeSubrow: function(arg_obj){ |
| 106 |
|
| 107 |
|
| 108 |
this._viewTables[arg_obj.viewIdx].push('<tr', this._getTableAttrs('tr'), '>'); |
| 109 |
return true; |
| 110 |
}, |
| 111 |
|
| 112 |
afterSubrow: function(arg_obj){ |
| 113 |
|
| 114 |
|
| 115 |
this._viewTables[arg_obj.viewIdx].push('</tr>'); |
| 116 |
}, |
| 117 |
|
| 118 |
handleCell: function(arg_obj){ |
| 119 |
|
| 120 |
|
| 121 |
var cell = arg_obj.cell; |
| 122 |
if(cell.hidden || array.indexOf(arg_obj.spCols, cell.index) >= 0){ |
| 123 |
|
| 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 |
|
| 144 |
|
| 145 |
array.forEach(this._viewTables, function(table){ |
| 146 |
table.push('</div>'); |
| 147 |
}); |
| 148 |
}, |
| 149 |
|
| 150 |
toString: function(){ |
| 151 |
|
| 152 |
|
| 153 |
var viewsHTML = array.map(this._viewTables, function(table){ |
| 154 |
return table.join(''); |
| 155 |
}).join(''); |
| 156 |
return ['<div style="position: relative;">', viewsHTML, '</div>'].join(''); |
| 157 |
} |
| 158 |
}); |
| 159 |
}); |