Docs
Getting Started
Working with Data
How Tos
Frameworks
How it's Made
Exporting Data
This article will demonstrate various ways to export your data. Let's get straight to the action! DataGridXL has two built-in methods that'll let you export grid data values to a downloadable file:
// create grid
var grid = new DataGridXL("grid", {
data: [ ... ]
});
someButton.onclick = function(){
grid.downloadDataAsCSV();
}
someOtherButton.onclick = function(){
grid.downloadDataAsJSON();
}
Both methods will download the entire grid's data to a file on the user's computer.
That's not always what you want. In many cases you'll want to pass the data to a Javascript function or to some server-side script.
Get the data
DataGridXL has two methods that return the data: getCellRangeData(...) & getCellRangeText(...). Both methods require a cellRange parameter.
// create grid
var grid = new DataGridXL("grid", {
data: [ ... ]
});
someButton.onclick = function(){
var values = grid.getCellRangeData(this.getCellSelection());
console.log('values inside cell selection', values);
}
The above code will return the values inside the user's cell selection in a 2D array.
Its sister method getCellRangeText will return the data as TSV (Tab Seperated Values), which is the common clipboard-format to copy/paste between spreadsheet applications.