Updated
This commit is contained in:
95
master/examples/test_grid_csv_export.html
Normal file
95
master/examples/test_grid_csv_export.html
Normal file
@@ -0,0 +1,95 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Test dojox.grid.Grid Basic</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
|
||||
<style type="text/css">
|
||||
@import "../resources/Grid.css";
|
||||
@import "../resources/tundraGrid.css";
|
||||
@import "../../../dojo/resources/dojo.css";
|
||||
@import "../../../dijit/themes/tundra/tundra.css";
|
||||
body {
|
||||
font-size: 0.9em;
|
||||
font-family: Geneva, Arial, Helvetica, sans-serif;
|
||||
}
|
||||
.heading {
|
||||
font-weight: bold;
|
||||
padding-bottom: 0.25em;
|
||||
}
|
||||
|
||||
#grid {
|
||||
border: 1px solid #333;
|
||||
width: 35em;
|
||||
height: 30em;
|
||||
}
|
||||
</style>
|
||||
<script type="text/javascript" src="../../../dojo/dojo.js"
|
||||
djConfig="isDebug:false, parseOnLoad: true"></script>
|
||||
<script type="text/javascript">
|
||||
dojo.require("dijit.dijit");
|
||||
dojo.require("dojox.grid.DataGrid");
|
||||
dojo.require("dojo.data.ItemFileWriteStore");
|
||||
dojo.require("dijit.form.Button");
|
||||
dojo.require("dojo.parser");
|
||||
</script>
|
||||
<script type="text/javascript" src="support/test_data.js"></script>
|
||||
<script type="text/javascript">
|
||||
var grid = null;
|
||||
var layout = [[
|
||||
new dojox.grid.cells.RowIndex({ name: "Index", width: 5 }),
|
||||
{name: 'Column 1', field: 'col1'},
|
||||
{name: 'Column 2', field: 'col2'},
|
||||
{name: 'Column 3', field: 'col3'},
|
||||
{name: 'Column 4', field: 'col4', width: "150px"},
|
||||
{name: 'Column 5', field: 'col5'}
|
||||
],[
|
||||
{name: 'Column 6', field: 'col6', colSpan: 2},
|
||||
{name: 'Column 7', field: 'col7'},
|
||||
{name: 'Column 8'},
|
||||
{name: 'Column 9', field: 'col3', colSpan: 2}
|
||||
]];
|
||||
var items_to_csv = function(items){
|
||||
var csvResults = dojo.byId('csvResults');
|
||||
var first_row = [];
|
||||
dojo.forEach(grid.layout.cells, function(cell){
|
||||
first_row.push(cell.name);
|
||||
});
|
||||
csvResults.value = first_row.join(',') + "\n";
|
||||
dojo.forEach(items, function(item, i){
|
||||
var result = [];
|
||||
dojo.forEach(grid.layout.cells, function(cell){
|
||||
result.push(cell.format(i, item));
|
||||
});
|
||||
csvResults.value += result.join(',') + "\n";
|
||||
});
|
||||
}
|
||||
var export_all = function(){
|
||||
var store = grid.store;
|
||||
store.fetch({
|
||||
query: grid.query,
|
||||
sort: grid.getSortProps(),
|
||||
queryOptions: grid.queryOptions,
|
||||
onComplete: function(items){
|
||||
items_to_csv(items);
|
||||
}
|
||||
});
|
||||
}
|
||||
var export_selected = function(){
|
||||
items_to_csv(grid.selection.getSelected());
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body class="tundra">
|
||||
<div class="heading">dojox.grid.Grid Basic Test</div>
|
||||
<button dojoType="dijit.form.Button" onClick="export_all">Export All</button>
|
||||
<button dojoType="dijit.form.Button" onClick="export_selected">Export Selected</button>
|
||||
|
||||
<div jsId="grid" id="grid" dojoType="dojox.grid.DataGrid"
|
||||
store="test_store" query="{ id: '*' }"
|
||||
structure="layout" rowSelector="20px"></div>
|
||||
|
||||
Results:<br />
|
||||
<textarea rows="20" cols="100" id="csvResults"></textarea>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user