| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 | "http://www.w3.org/TR/html4/loose.dtd"> |
| 3 | <html> |
| 4 | <head> |
| 5 | <title>dojox.grid.Grid Sizing Example</title> |
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> |
| 7 | <style type="text/css"> |
| 8 | @import "../../../dojo/resources/dojo.css"; |
| 9 | @import "../resources/Grid.css"; |
| 10 | @import "../resources/tundraGrid.css"; |
| 11 | |
| 12 | .heading { |
| 13 | font-weight: bold; |
| 14 | padding-bottom: 0.25em; |
| 15 | } |
| 16 | |
| 17 | #container { |
| 18 | width: 400px; |
| 19 | height: 200px; |
| 20 | border: 4px double #333; |
| 21 | } |
| 22 | |
| 23 | #grid { |
| 24 | border: 1px solid #333; |
| 25 | } |
| 26 | </style> |
| 27 | <script type="text/javascript" src="../../../dojo/dojo.js" |
| 28 | data-dojo-config="isDebug: true, parseOnLoad: true"></script> |
| 29 | <script type="text/javascript"> |
| 30 | dojo.require("dijit.dijit"); |
| 31 | dojo.require("dojox.grid.DataGrid"); |
| 32 | dojo.require("dojo.data.ItemFileWriteStore"); |
| 33 | dojo.require("dojo.parser"); |
| 34 | </script> |
| 35 | <script type="text/javascript" src="support/test_data.js"></script> |
| 36 | <script type="text/javascript"> |
| 37 | var structure = [ |
| 38 | { |
| 39 | noscroll: false, |
| 40 | cells: [ |
| 41 | {name: 'Column 1', field: 'col1'}, |
| 42 | {name: 'Column 2', field: 'col2'} |
| 43 | ] |
| 44 | }, |
| 45 | [ |
| 46 | {name: 'Column 3', field: 'col3'}, |
| 47 | {name: 'Column 4', field: 'col4'}, |
| 48 | {name: 'Column 5', field: 'col5'}, |
| 49 | {name: 'Column 6', field: 'col6'}, |
| 50 | {name: 'Column 7', field: 'col7'} |
| 51 | ] |
| 52 | ]; |
| 53 | |
| 54 | // get can return data for each cell of the grid |
| 55 | function get(inRowIndex) { |
| 56 | return [this.index, inRowIndex].join(', '); |
| 57 | } |
| 58 | |
| 59 | function resizeInfo() { |
| 60 | setTimeout(function() { |
| 61 | dojo.byId('gridWidth').value = grid.domNode.clientWidth; |
| 62 | dojo.byId('gridHeight').value = grid.domNode.clientHeight; |
| 63 | }, 1); |
| 64 | } |
| 65 | |
| 66 | function resizeGrid() { |
| 67 | grid.set('autoHeight', false); |
| 68 | grid.set('autoWidth', false); |
| 69 | var |
| 70 | w = Number(dojo.byId('gridWidth').value), |
| 71 | h = Number(dojo.byId('gridHeight').value); |
| 72 | |
| 73 | dojo.contentBox(grid.domNode, {w: w, h: h}); |
| 74 | grid.update(); |
| 75 | } |
| 76 | |
| 77 | function fitWidth() { |
| 78 | grid.set('autoHeight', false); |
| 79 | grid.set('autoWidth', true); |
| 80 | grid.update(); |
| 81 | } |
| 82 | |
| 83 | function fitHeight() { |
| 84 | grid.set('autoHeight', true); |
| 85 | grid.set('autoWidth', false); |
| 86 | grid.update(); |
| 87 | } |
| 88 | |
| 89 | function fitBoth() { |
| 90 | grid.set('autoHeight', true); |
| 91 | grid.set('autoWidth', true); |
| 92 | grid.update(); |
| 93 | } |
| 94 | |
| 95 | function sizeDefault() { |
| 96 | grid.set('autoHeight', false); |
| 97 | grid.set('autoWidth', false); |
| 98 | grid.domNode.style.width = ''; |
| 99 | grid.domNode.style.height = 0; |
| 100 | grid.update(); |
| 101 | } |
| 102 | |
| 103 | dojo.addOnLoad(function() { |
| 104 | dojo.byId('gridWidth').value = 500; |
| 105 | dojo.byId('gridHeight').value = 200; |
| 106 | dojo.connect(grid, 'update', resizeInfo); |
| 107 | resizeGrid(); |
| 108 | }); |
| 109 | </script> |
| 110 | </head> |
| 111 | <body class="tundra"> |
| 112 | <div class="heading">dojox.grid.Grid Sizing Test</div> |
| 113 | Grid width: <input id="gridWidth" type="text"> |
| 114 | and height: <input id="gridHeight" type="text"> |
| 115 | <button onclick="resizeGrid()">Resize Grid</button><br><br> |
| 116 | <button onclick="fitWidth()">Fit Data Width</button> |
| 117 | <button onclick="fitHeight()">Fit Data Height</button> |
| 118 | <button onclick="fitBoth()">Fit Data Width & Height</button> |
| 119 | <button onclick="sizeDefault()">DefaultSize</button><br><br> |
| 120 | <div id="grid" data-dojo-id="grid" dojoType="dojox.grid.DataGrid" |
| 121 | autoWidth="true" autoHeight="true" store="test_store" |
| 122 | structure="structure" elasticView="2"></div> |
| 123 | |
| 124 | <p>Grid fits to a sized container by default:</p> |
| 125 | <div id="container"> |
| 126 | <div id="grid1" data-dojo-id="grid1" dojoType="dojox.grid._Grid" |
| 127 | get="get" structure="structure" rowCount="10" elasticView="2"></div> |
| 128 | </div> |
| 129 | |
| 130 | <p> Grid is essentially hidden (height of zero) when parent container is unsized |
| 131 | (nothing, including the header, should be displayed):</p> |
| 132 | <div id="unsizedContainer"> |
| 133 | <div id="grid2" dojoType="dojox.grid._Grid" |
| 134 | get="get" structure="structure" rowCount="10" elasticView="2"></div> |
| 135 | </div> |
| 136 | |
| 137 | <p> Grid is autoHeight and autoWidth via markup</p> |
| 138 | <div id="grid3" dojoType="dojox.grid._Grid" |
| 139 | autoWidth="true" autoHeight="true" get="get" |
| 140 | structure="structure" rowCount="10" elasticView="2"></div> |
| 141 | </body> |
| 142 | </html> |