This works extremely well. Thank you! The only real change I made was to define my dataTable as a global variable so it could be passed from the button click.
I do not intend to use a URL datasource so the toolbar does not seem to be the right solution for me. I want to try it with a dataview so I will need to investigate how to get a databiew object from a table that has been sorted and filtered... On Apr 20, 10:47 pm, knight <[email protected]> wrote: > 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"); > > } > > On Apr 20, 7:21 pm, T-Roy <[email protected]> wrote: > > > > > > > > > Does anyone know of a way to provide a data download capability for a > > resident data table or data view? > > > Ideally it would provide csv or json data that is filtered and sorted > > in accordance with the currently displayed data view in a dashboard. > > > Thanks for any ideas! -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.
