Exporting Content and Data

You can export components to PNG, Excel, PDF, and CSV formats.

Export is available both in Standard and Pro versions

Basic Export

Components do not require any special configuration to be exported. To export a component to one of the supported formats, call the related method, e.g.:

webix.ui({
    view:"list",
    id: "mylist",
    // list configuration
});
 
webix.toExcel($$("mylist"));

Returning a Promise with Data

The export methods return promise objects. The promise is resolved with the contents of a file which is ready for downloading. So, if needed, you can access the raw data of the exported file (a blob object). For example:

webix.toPNG($$("mylist")).then(function(blob){
    // the logic of processing the blob
});

For example, you may need to disable file download and process raw data according to your needs.

General Customization Settings

All four export methods have some customization settings in common:

Disabling file download

You can disable the download of a file via the download property set to false:

webix.toPNG($$("table"), {
   download:false
}).then(function(blob){
   //process raw data
});

Ignoring particular datatable columns during export

You can omit some columns from export. Pass the ignore property as a hash of column that must be ignored. For example:

webix.toCSV($$("table"), {
    ignore: { "votes":true, "rating":true }
});

Stripping HTML tags from cells

Works for Excel, PDF, CSV

You can strip all HTML tags from the cell contents with the filterHTML setting:

webix.toExcel($$("table"), {
    filterHTML:true
});

Setting columns you'd like to see in the export file

Works for Excel, PDF, CSV

There are two ways to set the custom columns for export, depending on whether the order of columns is important to you.

  • for an automatic column order, provide a hash with column IDs as keys. The values can be either boolean for default parameters (taken from component configuration) or objects with custom parameters. E.g. if you want to export these columns:
webix.toCSV($$("table"), {
    columns:{
        "rank":true,
        "title":{ header:"Title", width:250 },
        "2016":{ header:"Votes in 2016" },
        "2015":{ header:"Votes in 2015" }
    }
});

The order in the export file will be: "2015", "2016", "rank", "title" since numbers are processed first and come in the ascending order, which probably is not what you expected.

  • for a strict column order in the output file, specify the columns as a plain array:
webix.toCSV($$("table"), {
    columns:[
        { id:"rank" },
        { id:"title", header:"Title", width:250 },
        { id:"2016", header:"Votes in 2016" },
        { id:"2015", header:"Votes in 2015" }
    ]
});

Note that if you want to get the default column's parameters in this case, you should specify only the column's id (see the "rank" column).

Including extra fields into export

Works for Excel, PDF, CSV

You can include extra fields into export by forming them within the export function:

webix.toPDF($$("mylist"), {
    columns:{
        Custom1:{
            template:function(obj){
                return "Year " + obj.year;
            },
            width:50,
            header:"Year"
        },
        //other columns
        title:true
    }
});

"Custom1" (any name can be used) receives the data from the year field even if it is not seen in this component but is presented in its dataset. The newly created column will have width, template, and header.

Including hidden columns and rows

Works for Excel, PDF, CSV

By default hidden columns and rows are not included during export. You can include them by setting the hidden property to true:

webix.toExcel($$("datatable1"), {
    hidden: true
});

When exporting data to excel format the hidden columns/rows will be initially hidden in the file. You can show them via the corresponding controls in the Excel tables.

Exporting to the PDF or CSV formats makes the hidden columns/rows visible in the exported file.

Filtering data for export

Works for Excel, PDF, CSV

To filter data for export, define the filter function that must return the data that should be exported:

webix.toCSV($$("data"), {
    filter:function(obj){
        var found = sel.find(function(item){
            return item.id == obj.id;
        });
        return found;
    }
});

Related sample:  Specifying Data Items for Export

Modifying data of exported items

Works for Excel, PDF, CSV

You can change data for export with the help of the $export key of the data scheme:

webix.ui({
    view:"list",
    id:"mylist",
    scheme:{
        $export:function(obj){
            return { value:obj.value, date:webix.i18n.parseFormatStr(obj.date) };
        }
    }
});
 
webix.toExcel($$("mylist"));

Related sample:  Changing Item Data in Export

Customizing Export to CSV for Hierarchical Components

Works for Excel, PDF, CSV

You can customize the output data of hierarchical components (Tree and Treetable) in the following way:

  • not rendering "hyphens" before child nodes in tree-like structures by using the plainOutput option with the true value
webix.toCSV($$("mytreetable"), {
    plainOutput:true
});
  • rendering separate columns for data on different hierarchy levels, thus rendering data in a table:
webix.toCSV($$("mytreetable"), {
    flatTree:{
        id:"value",
        columns:[
            { header:"Title" },
            { header:"Section" },
            { header:"Subsection" }
        ]
    }
});

The flatTree property object includes the following options:

  • id (string) - the data property that will be rendered in columns
  • columns (array) - the array with columns, to which the above data property will be distributed according to the hierarchy level
  • fill (boolean, optional) - if true, allows filling child records with parent data for each child node

Related sample:  Export to PDF, Excel

Customizing Export Details

Back to top