v7.3.0
SupportExamplesFree Trial

ExcelExporter
Feature

A feature that allows exporting Grid data to Excel or CSV without involving the server. It uses TableExporter class as data provider, 3rd party provider to generate XLS files, and Microsoft XML specification.

import WriteExcelFileProvider from '../../lib/Grid/feature/experimental/xlsproviders/WriteExcelFileProvider.js';

new Grid({ features : { excelExporter : { xlsProvider : WriteExcelFileProvider } } });

Implementing custom provider

// Global scope
<script src="https://cdn.jsdelivr.net/npm/write-excel-file/bundle/write-excel-file.min.js"></script>
// importing from package
import writeXlsxFile from 'write-excel-file';

const typeMap = { string : String, number : Number, date : Date };

class MyXlsProvider { static write({ filename, columns, rows }) { columns.forEach(col => delete col.type); rows.forEach(row => row.forEach(cell => cell.type = typeMap[cell.type] || String));

globalThis.writeXlsxFile([columns, ...rows], { // write-excel-file uses amount of symbols as width, so we need to convert pixels to symbols columns : columns.map(col => ({ ...col, width : Math.round(col.width / 10) })), fileName : filename, dateFormat : 'yyyy-mm-dd' }); } }

const grid = new Grid({ features : { excelExporter : { xlsProvider : MyXlsProvider } } })

Here is an example of how to add the feature:

const grid = new Grid({
    features : {
        excelExporter : {
            // Choose the date format for date fields
            dateFormat : 'YYYY-MM-DD HH:mm',

exporterConfig : { // Choose the columns to include in the exported file columns : ['name', 'role'], // Optional, export only selected rows rows : grid.selectedRecords } } } });

And how to call it:

grid.features.excelExporter.export({
    filename       : 'Export',
    exporterConfig : {
        columns : [
            { text : 'First Name', field : 'firstName', width : 90 },
            { text : 'Age', field : 'age', width : 40 },
            { text : 'Starts', field : 'start', width : 140 },
            { text : 'Ends', field : 'finish', width : 140 }
        ]
    }
})

Exporting to CSV is done with the csv config:

grid.features.excelExporter.export({
    filename : 'myfile',
    csv      : true
})

This feature is disabled by default. For info on enabling it, see GridFeatures.

This feature will not work properly when Store uses lazyLoad
This class requires a 3rd party library to export to XLSX

See also

No results

Configs

Configs are options you supply in a configuration object when creating an instance of this class
  • If this config is true, exporter will convert all empty values to ''. Empty values are:

    • undefined, null, NaN
    • Objects/class instances that do not have toString method defined and are stringified to [object Object]
    • functions
  • csvMimeType : Stringtext/csv
    internal

    Allows configuring MIME type of the exported CSV file

  • Defines how dates in a cell will be formatted

  • Set this config to true to export all exportable columns including hidden columns as well.

  • Exporter class to use as a data provider. TableExporter by default.

  • Configuration object for exporter class.

  • Name of the exported file

  • Internal listeners, that cannot be removed by the user.

  • The widget which this plugin is to attach to.

    Has a corresponding runtime client property.

  • Set to false to disable localization of this object.

Properties

Properties are getters/setters or publicly accessible variables on this class
  • isEvents : Booleantrue
    READONLY
    static
    ADVANCED
    Events
    Identifies an object as an instance of Events class, or subclass thereof.
  • isExcelExporter : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of ExcelExporter class, or subclass thereof.
  • isLocalizable : Booleantrue
    READONLY
    static
    ADVANCED
    Localizable
    Identifies an object as an instance of Localizable class, or subclass thereof.
  • properties : Object
    internal
    static
    InstancePlugin

    A class property getter for the default values of internal properties for this class.

  • emptyArray : Array
    internal
    READONLY
    InstancePlugin

    An empty array that can be used as a default value.

  • emptyObject : Object
    internal
    READONLY
    InstancePlugin

    An empty object that can be used as a default value.

  • isExcelExporter : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of ExcelExporter class, or subclass thereof.
  • isInstancePlugin : Booleantrue
    READONLY
    ADVANCED
    InstancePlugin
    Identifies an object as an instance of InstancePlugin class, or subclass thereof.
  • config : Object
    READONLY
    ADVANCED
    InstancePlugin

    Returns a copy of the full configuration which was used to configure this object.

  • This property is set to true before the constructor returns.

  • isDestroying : Boolean
    READONLY
    ADVANCED
    InstancePlugin

    This property is set to true on entry to the destroy method. It remains on the objects after returning from destroy(). If isDestroyed is true, this property will also be true, so there is no need to test for both (for example, comp.isDestroying || comp.isDestroyed).

  • client : Widget
    READONLY
    ADVANCED
    InstancePlugin

    The Widget which was passed into the constructor, which is the Widget we are providing extra services for.

    Has a corresponding client config.

  • Get the global LocaleHelper

  • Get the global LocaleManager

Functions

Functions are methods available for calling on the class
  • onClassMixedIn( )
    internal
    static
    InstancePlugin

    This optional class method is called when a class is mixed in using the mixin() method.

  • initClass( )
    static
    ADVANCED
    InstancePlugin

    Registers this class type with its Factory

  • Internal function used to hook destroy() calls when using thisObj

  • Internal function used restore hooked destroy() calls when using thisObj

  • doDestroy( )
    internal
    Events

    Auto detaches listeners registered from start, if set as detachable

  • once( )
    private
    Events

    Internal function used to run a callback function after an event is triggered

  • Removes all listeners registered to this object by the application.

  • This will merge a feature's (subclass of InstancePlugin) keyMap with it's client's keyMap.

Events

Events are triggered for certain actions in this class and can be listened for to react to those actions in your code

Event handlers

Event handlers are callbacks called as a result of certain actions in this class

Type definitions

id: excelExporter

Source path

Grid/feature/experimental/ExcelExporter.js

Demo

examples/exporttoexcel

Contents