You can export components to PNG, Excel, PDF, and CSV formats.
Export is available both in Standard and Pro versions
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"));
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.
All four export methods have some customization settings in common:
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
});
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 }
});
Works for Excel, PDF, CSV
You can strip all HTML tags from the cell contents with the filterHTML setting:
webix.toExcel($$("table"), {
filterHTML:true
});
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.
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.
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).
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.
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.
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
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
Works for Excel, PDF, CSV
You can customize the output data of hierarchical components (Tree and Treetable) in the following way:
webix.toCSV($$("mytreetable"), {
plainOutput:true
});
webix.toCSV($$("mytreetable"), {
flatTree:{
id:"value",
columns:[
{ header:"Title" },
{ header:"Section" },
{ header:"Subsection" }
]
}
});
The flatTree property object includes the following options:
Related sample: Export to PDF, Excel