123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- /*
- Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
- Available via Academic Free License >= 2.1 OR the modified BSD license.
- see: http://dojotoolkit.org/license for details
- */
- if(!dojo._hasResource["dojox.grid.enhanced.plugins.exporter.TableWriter"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
- dojo._hasResource["dojox.grid.enhanced.plugins.exporter.TableWriter"] = true;
- dojo.provide("dojox.grid.enhanced.plugins.exporter.TableWriter");
- dojo.require("dojox.grid.enhanced.plugins.exporter._ExportWriter");
- dojox.grid.enhanced.plugins.Exporter.registerWriter("table",
- "dojox.grid.enhanced.plugins.exporter.TableWriter");
-
- dojo.declare("dojox.grid.enhanced.plugins.exporter.TableWriter",
- dojox.grid.enhanced.plugins.exporter._ExportWriter, {
- // summary:
- // Export grid to HTML table format. Primarily used by Printer plugin.
- constructor: function(/* object? */writerArgs){
- // summary:
- // The generated table only defines the col/rowspan, height and width of
- // all the cells in the style attribute, no other attributes
- // (like border, cellspacing, etc.) are used.
- // Users can define these attributes in the writerArgs object, like:
- // {table:"border='border'",thead:"cellspacing='3'"}
- this._viewTables = [];
- this._tableAttrs = writerArgs || {};
- },
- _getTableAttrs: function(/* string */tagName){
- // summary:
- // Get html attribute string for the given kind of tag.
- // tags:
- // private
- // tagName: string
- // An html tag name
- // returns:
- // The well formatted attributes for the given html table.tag
- var attrs = this._tableAttrs[tagName] || '';
- //To ensure the attribute list starts with a space
- if(attrs && attrs[0] != ' '){
- attrs = ' ' + attrs;
- }
- return attrs; //String
- },
- _getRowClass: function(/* object */arg_obj){
- // summary:
- // Get CSS class string for a row
- // tags:
- // private
- return arg_obj.isHeader ? " grid_header" : [//String
- " grid_row grid_row_",
- arg_obj.rowIdx + 1,
- arg_obj.rowIdx % 2 ? " grid_even_row" : " grid_odd_row"
- ].join('');
- },
- _getColumnClass: function(/* object */arg_obj){
- // summary:
- // Get CSS class string for a column
- // tags:
- // private
- var col_idx = arg_obj.cell.index + arg_obj.colOffset + 1;
- return [" grid_column grid_column_", col_idx,//String
- col_idx % 2 ? " grid_odd_column" : " grid_even_column"].join('');
- },
- beforeView: function(/* object */arg_obj){
- // summary:
- // Overrided from _ExportWriter
- var viewIdx = arg_obj.viewIdx,
- table = this._viewTables[viewIdx],
- height, width = dojo.marginBox(arg_obj.view.contentNode).w;
- if(!table){
- var left = 0;
- for(var i = 0; i < viewIdx; ++i){
- left += this._viewTables[i]._width;
- }
- table = this._viewTables[viewIdx] = ['<div class="grid_view" style="position: absolute; top: 0; ',
- dojo._isBodyLtr() ? 'left' : 'right', ':', left,
- 'px;">'];
- }
- table._width = width;
- if(arg_obj.isHeader){
- height = dojo.contentBox(arg_obj.view.headerContentNode).h;
- }else{
- var rowNode = arg_obj.grid.getRowNode(arg_obj.rowIdx);
- if(rowNode){
- height = dojo.contentBox(rowNode).h;
- }else{
- //This row has not been loaded from store, so we should estimate it's height.
- height = arg_obj.grid.scroller.averageRowHeight;
- }
- }
- table.push('<table class="', this._getRowClass(arg_obj),
- '" style="table-layout:fixed; height:', height, 'px; width:', width, 'px;" ',
- 'border="0" cellspacing="0" cellpadding="0" ',
- this._getTableAttrs("table"),
- '><tbody ', this._getTableAttrs('tbody'), '>');
- return true; //Boolean
- },
- afterView: function(/* object */arg_obj){
- // summary:
- // Overrided from _ExportWriter
- this._viewTables[arg_obj.viewIdx].push('</tbody></table>');
- },
- beforeSubrow: function(/* object */arg_obj){
- // summary:
- // Overrided from _ExportWriter
- this._viewTables[arg_obj.viewIdx].push('<tr', this._getTableAttrs('tr'), '>');
- return true; //Boolean
- },
- afterSubrow: function(/* object */arg_obj){
- // summary:
- // Overrided from _ExportWriter
- this._viewTables[arg_obj.viewIdx].push('</tr>');
- },
- handleCell: function(/* object */arg_obj){
- // summary:
- // Overrided from _ExportWriter
- var cell = arg_obj.cell;
- if(cell.hidden || dojo.indexOf(arg_obj.spCols, cell.index) >= 0){
- //We are not interested in indirect selectors and row indexes.
- return;
- }
- var cellTagName = arg_obj.isHeader ? 'th' : 'td',
- attrs = [cell.colSpan ? ' colspan="' + cell.colSpan + '"' : '',
- cell.rowSpan ? ' rowspan="' + cell.rowSpan + '"' : '',
- ' style="width: ', dojo.contentBox(cell.getHeaderNode()).w, 'px;"',
- this._getTableAttrs(cellTagName),
- ' class="', this._getColumnClass(arg_obj), '"'].join(''),
- table = this._viewTables[arg_obj.viewIdx];
- table.push('<', cellTagName, attrs, '>');
- if(arg_obj.isHeader){
- table.push(cell.name || cell.field);
- } else{
- table.push(this._getExportDataForCell(arg_obj.rowIdx, arg_obj.row, cell, arg_obj.grid));
- }
- table.push('</', cellTagName, '>');
- },
- afterContent: function(){
- // summary:
- // Overrided from _ExportWriter
- dojo.forEach(this._viewTables, function(table){
- table.push('</div>');
- });
- },
- toString: function(){
- // summary:
- // Overrided from _ExportWriter
- var viewsHTML = dojo.map(this._viewTables, function(table){ //String
- return table.join('');
- }).join('');
- return ['<div style="position: relative;">', viewsHTML, '</div>'].join('');
- }
- });
- }
|