To export data from DataTable/TreeTable into an Excel document, you need to call the toExcel method. The method takes 2 parameters:
For example, to export a datatable to an Excel document, you need to start with the view initialization:
{
view:"datatable",
id: "myDatatable",
// datatable configuration
...
}
And then the call of the toExcel() method should follow:
webix.toExcel($$("myDataTable"));
Related sample: Export to Excel
By default:
You can change the default behavior and add some other settings.
You can
Below you will find detailed descriptions of export possibilities:
webix.toExcel($$("table"), {
filename: "table", // for filename
name: "Films" // for sheet name
});
Related sample: Export to Excel
webix.toExcel($$("table"), {
filterHTML:true
});
You can provide an object with column ids as keys. Their values can be either boolean for default parameters (taken from component configuration) or object for custom parameters:
webix.toExcel($$("table"), {
columns:{
"rank":true,
"title":{ header:"Title", width:250}
}
});
With such a notation, the order of the columns in the resulting file is defined automatically with a for.. in loop. Sometimes it may be unreliable, e.g.:
webix.toExcel($$("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.
To ensure the strict order of columns in the resulting file, you can specify the columns as a plain array:
webix.toExcel($$("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).
webix.toExcel($$("myDataTable"), {
columns:{
"title":{header: "Title", width: 200, template: webix.template("#id#.#name#")},
"year":{header: "Year", width: 100}
}
});
The column will be rendered with the stated additional properties, which may differ from the component's parameters.
webix.toExcel(datatable, {
columns:{
Custom1:{
template:function(obj){
return "Year " + obj.year;
},
width:50,
header:"Year"
},
// other columns
title:true
}
});
"Custom1" (any name can be used) receives data from the year field even if it is not seen in this datatable but is presented in its dataset. The field is rendered with width, template and header that will be the header of the corresponding column in the export table.
webix.ui({
rows:[
{
view:"datatable",
id:"table",
data:grid_data,
columns:[
{id:"title", fillspace:true, template:"Film #title#"}
]
}
]
});
webix.toExcel($$("table"), {
rawValues:true
});
By default, the rawValues option is set to false and the template set in the dataset is rendered.
webix.toExcel($$("table"), {
spans:true
});
Note that only spans applied to columns' headers will be exported, since the DataTable rowspans and colspans functionality is the feature available only in the PRO version.
webix.toExcel($$("table"), {
download:false
}).then(function(blob){
// process raw data
});
webix.toExcel($$("table"), {
ignore: { "votes":true, "rating":true }
});
webix.toExcel($$("table"), {
hidden: true
});
The hidden columns/rows will be initially hidden in the exported file. You can show them via the corresponding controls in Excel.
webix.toExcel(table, {
hide:(obj)=>{
if(obj.id < 20)return true;
}
});
The callback receives a row object as a parameter.
To hide a particular column set the hidden field to the config object of the desired column to true:
webix.toExcel($$("table"), {
columns:{
rank:true,
// title column will be hidden
title:{ width:1500, hidden:true },
year:true,
votes:true
}
});
Related sample: Datatable: Hiding Cols/Rows during Export to Excel
webix.toExcel($$("table"), {
styles:true
});
webix.toExcel($$("table"), {
heights:true
});
If the styles:true option is set, the heights option is automatically set to "all".
webix.toExcel($$("table"), {
header:false,
footer:false
});
webix.toExcel($$("data"), {
filter:function(obj){
return obj.checked;
}
});
Related sample: Specifying Data Items for Export
webix.toExcel($$("table"), {
rawValues:true,
columns:[
{ id:"year", header:"Released", exportType:"date", exportFormat:"d-mmm-yy"},
{ id:"votes", header:"Votes", exportType:"number", exportFormat:"#,##0.00"}
]
});
Related sample: Export to Excel: Setting Format
webix.ui({
rows: [
{
id: "table",
view:"datatable",
autoConfig:true,
leftSplit:1,
topSplit:2,
data:big_film_set
},
]
});
webix.toExcel($$("table"), {
freeze:true
});
Related sample: Export to Excel: Frozen Rows/Columns
Check the following example:
Related sample: Exporting a table with images to Excel
Back to top