HI All My requirement is To show a table( google interactive ) And download data of shown table in csv format. I am using php. My question is how will i create a datasource in mylocal syatem ? What should be extension of datasourc开发者_StackOverflow中文版e file ? how will i write data in datasource? How will i populate table wit this data ? give a option to users to download it in csv format
To generate the table you'll want to check out the Google Charts Table documentation. The code to generate a table will look something like:
<head>
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
google.load('visualization', '1', {packages:['table']});
google.setOnLoadCallback(drawTable);
function drawTable() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('number', 'Salary');
data.addColumn('boolean', 'Full Time Employee');
data.addRows(2);
data.setCell(0, 0, 'Mike');
data.setCell(0, 1, 10000, '$10,000');
data.setCell(0, 2, true);
data.setCell(1, 0, 'Jim');
data.setCell(1, 1, 8000, '$8,000');
data.setCell(1, 2, false);
var table = new google.visualization.Table(document.getElementById('table_div'));
table.draw(data, {showRowNumber: true});
}
</script>
</head>
<div id='table_div'></div>
The data you're populating the table with will theoretically need to be stored server-side already. You can store the data in a database such as a MySQL database, of which there are many tutorials online on how to set one up.
There are a number of ways to convert the data into a .csv file server-side. As an example, using PHP you could use fputcsv, by creating an arbitrary .csv file path on your server, then reading the data from your database to populate the .csv file. See the fputscsv documentation for examples on how to properly do this.
精彩评论