Hi,
I have written this JS function called getCSV() to offer CSV download
of a data table, using various pointers on the web.
Just call this based on a button click or some event. I have not
tested this with a data view yet.
String.prototype.EntityDecode = function() // For Converting HTML
encoded chars to normal form
{
var t = document.createElement( 'div' );
t.innerHTML = this;
return t.firstChild.nodeValue;
}
function getCSV(dataTable) {
var rows = dataTable.getNumberOfRows();
var cols = dataTable.getNumberOfColumns();
var str = '';
// header
for (var j = 0; j < cols; j++) {
str += '"' + dataTable.getColumnLabel(j) + '"';
if (j != cols - 1) { str += ',';};
}
str += '\n';
// data
for (var i = 0; i < rows; i++) {
for (var j = 0; j < cols; j++) {
var d = new String(dataTable.getValue(i, j));
if (d.search("\&") != -1) {
str += '"' + d.EntityDecode() + '"';
} else
str += '"' + d + '"';
if (j != cols - 1) { str += ',';};
}
str += '\n';
}
window.open( "data:text/csv;charset=utf-8," + escape(str),
"csvWindow");