dojox/grid/enhanced/plugins/Exporter.js

  • Provides:

    • dojox.grid.enhanced.plugins.Exporter
  • Requires:

    • dojox.grid.enhanced._Plugin in common
    • dojox.grid._RowSelector in common
  • dojox.grid.enhanced.plugins.Exporter

    • type
      Function
    • chains:
      • dojox.grid.enhanced._Plugin: (prototype)
      • dojox.grid.enhanced._Plugin: (call)
    • summary
      only newed by _Plugin
    • example
      
      	function onExported(exported_text){
      		//custom code here...
      	}
      	dijit.byId("my_grid_id").exportTo("csv",	//registered export format, mandatory
      		{										//the whole object is optional.
      			fetchArgs: {start:0,count:1000},	//keywordArgs for fetch, optional
      			writerArgs: {separator:';'},		//export writer specific arguments, optional
      		},
      		function(str){
      			//call back function, mandatory
      	});
      	var result = dijit.byId("my_grid_id").exportSelectedTo("table",     //registered export format, mandatory
      														{separator:'|'} //export writer specific arguments, optional
      	);
    • parameters:
      • grid: (typeof EnhancedGrid)
        The grid to plug in to.
      • args: (typeof )
    • source: [view]
        this.grid = grid;
        this.formatter = (args && dojo.isObject(args)) && args.exportFormatter;
        this._mixinGrid();
  • dojox.grid.enhanced.plugins.Exporter.name

    • type
      String
    • summary
      Plugin name.
  • dojox.grid.enhanced.plugins.Exporter._mixinGrid

    • type
      Function
    • source: [view]
        var g = this.grid;
        g.exportTo = dojo.hitch(this, this.exportTo);
        g.exportGrid = dojo.hitch(this, this.exportGrid);
        g.exportSelected = dojo.hitch(this, this.exportSelected);
        g.setExportFormatter = dojo.hitch(this, this.setExportFormatter);
    • summary
  • dojox.grid.enhanced.plugins.Exporter.setExportFormatter

    • type
      Function
    • parameters:
      • formatter: (typeof )
    • source: [view]
        this.formatter = formatter;
    • summary
  • dojox.grid.enhanced.plugins.Exporter.exportGrid

    • type
      Function
    • parameters:
      • type: (typeof string)
        A registered export format name
      • args: (typeof object)
        includes:
        {
        fetchArgs: object?
        Any arguments for store.fetch
        writerArgs: object?
        Arguments for the given format writer
        }
      • onExported: (typeof function(string)
        Call back function when export result is ready
    • source: [view]
        if(dojo.isFunction(args)){
         onExported = args;
         args = {};
        }
        if(!dojo.isString(type) || !dojo.isFunction(onExported)){
         return;
        }
        args = args || {};
        var g = this.grid, _this = this,
         writer = this._getExportWriter(type, args.writerArgs),
         fetchArgs = (args.fetchArgs && dojo.isObject(args.fetchArgs)) ? args.fetchArgs : {},
         oldFunc = fetchArgs.onComplete;
        if(g.store){
         fetchArgs.onComplete = function(items, request){
          if(oldFunc){
           oldFunc(items, request);
          }
          onExported(_this._goThroughGridData(items, writer));
         };
         fetchArgs.sort = fetchArgs.sort || g.getSortProps();
         g._storeLayerFetch(fetchArgs);
        }else{
         //Data is defined directly in the structure;
         var start = fetchArgs.start || 0,
          count = fetchArgs.count || -1,
          items = [];
         for(var i = start; i != start + count && i < g.rowCount; ++i){
          items.push(g.getItem(i));
         }
         onExported(this._goThroughGridData(items, writer));
        }
    • summary
      Export required rows(fetchArgs) to a kind of format(type)
      using the corresponding writer with given arguments(writerArgs),
      then pass the exported text to a given function(onExported).
    • tags:
  • dojox.grid.enhanced.plugins.Exporter.exportSelected

    • type
      Function
    • parameters:
      • type: (typeof string)
        A registered export format name
      • writerArgs: (typeof object)
        Arguments for the given format writer
    • source: [view]
        if(!dojo.isString(type)){
         return "";
        }
        var writer = this._getExportWriter(type, writerArgs);
        return this._goThroughGridData(this.grid.selection.getSelected(), writer); //String
    • summary
      Only export selected rows.
    • tags:
    • return_summary
      string
      The exported string
    • returns
      String
  • dojox.grid.enhanced.plugins.Exporter._buildRow

    • type
      Function
    • parameters:
      • arg_obj: (typeof object)
      • writer: (typeof ExportWriter)
    • source: [view]
        var _this = this;
        dojo.forEach(arg_obj._views, function(view, vIdx){
         arg_obj.view = view;
         arg_obj.viewIdx = vIdx;
         if(writer.beforeView(arg_obj)){
          dojo.forEach(view.structure.cells, function(subrow, srIdx){
           arg_obj.subrow = subrow;
           arg_obj.subrowIdx = srIdx;
           if(writer.beforeSubrow(arg_obj)){
            dojo.forEach(subrow, function(cell, cIdx){
             if(arg_obj.isHeader && _this._isSpecialCol(cell)){
              arg_obj.spCols.push(cell.index);
             }
             arg_obj.cell = cell;
             arg_obj.cellIdx = cIdx;
             writer.handleCell(arg_obj);
            });
            writer.afterSubrow(arg_obj);
           }
          });
          writer.afterView(arg_obj);
         }
        });
    • summary
      Use the given export writer(writer) to go through a single row
      which is given in the context object(arg_obj).
    • tags:
    • return_summary
      undefined
  • dojox.grid.enhanced.plugins.Exporter._goThroughGridData

    • type
      Function
    • parameters:
      • items: (typeof Array)
      • writer: (typeof ExportWriter)
    • source: [view]
        var grid = this.grid,
         views = dojo.filter(grid.views.views, function(view){
          return !(view instanceof dojox.grid._RowSelector);
         }),
         arg_obj = {
          'grid': grid,
          'isHeader': true,
          'spCols': [],
          '_views': views,
          'colOffset': (views.length < grid.views.views.length ? -1 : 0)
         };
        //go through header
        if(writer.beforeHeader(grid)){
         this._buildRow(arg_obj,writer);
         writer.afterHeader();
        }
        //go through content
        arg_obj.isHeader = false;
        if(writer.beforeContent(items)){
         dojo.forEach(items, function(item, rIdx){
          arg_obj.row = item;
          arg_obj.rowIdx = rIdx;
          if(writer.beforeContentRow(arg_obj)){
           this._buildRow(arg_obj, writer);
           writer.afterContentRow(arg_obj);
          }
         }, this);
         writer.afterContent();
        }
        return writer.toString();
    • summary
      Use the given export writer(writer) to go through the grid structure
      and the given rows(items), then return the writer output.
    • tags:
  • dojox.grid.enhanced.plugins.Exporter._isSpecialCol

    • type
      Function
    • parameters:
      • header_cell: (typeof dojox.grid.__CellDef)
    • source: [view]
        return header_cell.isRowSelector || header_cell instanceof dojox.grid.cells.RowIndex; //Boolean
    • summary
      Row selectors and row indexes should be recognized and handled separately.
    • tags:
    • returns
      Boolean
  • dojox.grid.enhanced.plugins.Exporter._getExportWriter

    • type
      Function
    • parameters:
      • fileType: (typeof string)
      • writerArgs: (typeof object)
    • source: [view]
        var writerName, cls,
         expCls = dojox.grid.enhanced.plugins.Exporter;
        if(expCls.writerNames){
         writerName = expCls.writerNames[fileType.toLowerCase()];
         cls = dojo.getObject(writerName);
         if(cls){
          var writer = new cls(writerArgs);
          writer.formatter = this.formatter;
          return writer; //ExportWriter
         }else{
          throw new Error('Please make sure class "' + writerName + '" is required.');
         }
        }
        throw new Error('The writer for "' + fileType + '" has not been registered.');
    • summary
      Use the given export format type(fileType)
      and writer arguments(writerArgs) to create
      a ExportWriter and return it.
    • tags:
    • returns
      ExportWriter
  • dojox.grid.enhanced.plugins.Exporter.formatter

    • summary
  • dojox.grid.enhanced.plugins.Exporter.grid

    • type
      EnhancedGrid
    • summary
      The grid to plug in to.
  • dojox.grid.enhanced.plugins.Exporter.registerWriter

    • type
      Function
    • parameters:
      • fileType: (typeof string)
      • writerClsName: (typeof string)
    • source: [view]
       var expCls = dojox.grid.enhanced.plugins.Exporter;
       expCls.writerNames = expCls.writerNames || {};
       expCls.writerNames[fileType] = writerClsName;
    • summary
      Register a writer(writerClsName) to a export format type(fileType).
      This function separates the Exporter from all kinds of writers.
    • tags:
  • dojox.grid.enhanced.plugins

    • type
      Object
    • summary
  • dojox.grid.enhanced

    • type
      Object
    • summary
  • dojox.grid

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary