You're looking at DataGridXL v1. Click here to go to the latest version.

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:

Javascript
// create grid
var grid = new DataGridXL("grid", {
	data: [ ... ] 
});

someButton.onclick = function(){
	grid.exportDataToCSV();
}

someOtherButton.onclick = function(){
	grid.exportDataToJSON();
}

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.

Javascript
// 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 getCellRangeText will return the data as TSV (Tab Seperated Values), which is the common clipboard-format to copy/paste between DataGridXL and any spreadsheet application.

More coming soon...


Leave email to receive latest updates!