dojo DataGrid使用(二)-----------动态构建grid<span style="font-weight: normal;"><span style="font-family:Microsoft YaHei;"><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="js/dojo/dojo/resources/dojo.css">
<link rel="stylesheet" href="js/dojo/dojox/grid/resources/tundraGrid.css">
<style>
#gridDiv {
height: 20em;
}
</style>
<script>dojoConfig = {async: true, parseOnLoad: false}</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dojo/domReady!'],
function(){
var sampleData = {
identifier: "pro_no",
items: [{pro_no:'2100', pro:'A Series', min_amount:346, max_amount:931, avg_amount:647},
{pro_no:'2200', pro:'B Series', min_amount:301, max_amount:894, avg_amount:608},
{pro_no:'2300', pro:'C Series', min_amount:456, max_amount:791, avg_amount:532},
{pro_no:'2400', pro:'D Series', min_amount:859, max_amount:2433, avg_amount:1840},
{pro_no:'2500', pro:'E Series', min_amount:459, max_amount:1433, avg_amount:1040} ]
};
var store = new dojo.data.ItemFileReadStore({data: sampleData});
/*set up layout*/
var layout = [[
{field: 'pro_no', name: 'Product Number' },
{field: 'pro', name: 'Product' },
{field: 'min_amount', name: 'Minimum Amount' },
{field: 'max_amount', name: 'Maximum Amount' },
{field: 'avg_amount', name: 'Average Amount' }
]];
/*create a new grid*/
var grid = new dojox.grid.DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'});
grid.placeAt("gridDiv");
grid.startup();
});
</script>
</head>
<body class="tundra">
<div class="heading">Second DataGrid3</div>
<div id="gridDiv"></div>
</body>
</html></span></span>
<span style="font-weight: normal;"><span style="font-family:Microsoft YaHei;"><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="js/dojo/dojo/resources/dojo.css">
<link rel="stylesheet" href="js/dojo/dojox/grid/resources/tundraGrid.css">
<style>
#gridDiv {
height: 20em;
}
</style>
<script>dojoConfig = {async: true, parseOnLoad: false}</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dojo/domReady!'],
function(){
var sampleData = {
identifier: "pro_no",
items: [{pro_no:'2100', pro:'A Series', min_amount:346, max_amount:931, avg_amount:647},
{pro_no:'2200', pro:'B Series', min_amount:301, max_amount:894, avg_amount:608},
{pro_no:'2300', pro:'C Series', min_amount:456, max_amount:791, avg_amount:532},
{pro_no:'2400', pro:'D Series', min_amount:859, max_amount:2433, avg_amount:1840},
{pro_no:'2500', pro:'E Series', min_amount:459, max_amount:1433, avg_amount:1040} ]
};
var store = new dojo.data.ItemFileReadStore({data: sampleData});
/*set up layout*/
var layout = [[
{field: 'pro_no', name: 'Product Number' },
{field: 'pro', name: 'Product' },
{field: 'min_amount', name: 'Minimum Amount' },
{field: 'max_amount', name: 'Maximum Amount' },
{field: 'avg_amount', name: 'Average Amount' }
]];
/*create a new grid*/
var grid = new dojox.grid.DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'});
grid.placeAt("gridDiv");
grid.startup();
});
</script>
</head>
<body class="tundra">
<div class="heading">Second DataGrid3</div>
<div id="gridDiv"></div>
</body>
</html></span></span>
--------------------------------------------------------------------------------------
方案2:
<span style="font-family:Microsoft YaHei;font-size:14px;"><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="js/dojo/dojo/resources/dojo.css">
<link rel="stylesheet" href="js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="js/dojo/dojox/grid/resources/tundraGrid.css">
<style>
/*Grid needs an explicit height by default*/
#gridDiv {
height: 20em;
}
</style>
<script>dojoConfig = {async: true, parseOnLoad: false}</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
<script>
require(['dojo/_base/lang', 'dojox/grid/DataGrid', 'dojo/data/ItemFileWriteStore', 'dojo/dom', 'dojo/domReady!'],
function(lang, DataGrid, ItemFileWriteStore, dom){
/*set up data store*/
var data = {
identifier: "id",
items: []
};
var data_list = [
{ col1: "normal", col2: false, col3: 'But are not followed by two hexadecimal', col4: 29.91},
{ col1: "important", col2: false, col3: 'Because a % sign always indicates', col4: 9.33},
{ col1: "important", col2: false, col3: 'Signs can be selectively', col4: 19.34}
];
var rows = 10;
for(var i = 0, l = data_list.length; i < rows; i++){
data.items.push(lang.mixin({ id: i+1 }, data_list[i%l]));
}
var store = new ItemFileWriteStore({data: data});
/*set up layout*/
var layout = [[
{'name': 'Column 1', 'field': 'id', 'width': '100px'},
{'name': 'Column 2', 'field': 'col2', 'width': '100px'},
{'name': 'Column 3', 'field': 'col3', 'width': '200px'},
{'name': 'Column 4', 'field': 'col4', 'width': '150px'}
]];
/*create a new grid*/
var grid = new DataGrid({
id: 'grid',
store: store,
structure: layout,
rowSelector: '20px'});
/*append the new grid to the div*/
grid.placeAt("gridDiv");
/*Call startup() to render the grid*/
grid.startup();
});
</script>
</head>
<body class="tundra">
<div class="heading">Second DataGrid3</div>
<div id="gridDiv"></div>
</body>
</html></span>