| 1 | <html> |
| 2 | <head> |
| 3 | <title>Test dojox.grid.DataGrid Basic</title> |
| 4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> |
| 5 | |
| 6 | <style type="text/css"> |
| 7 | @import "../../../dojo/resources/dojo.css"; |
| 8 | @import "../../../dijit/themes/tundra/tundra.css"; |
| 9 | @import "../resources/Grid.css"; |
| 10 | @import "../resources/tundraGrid.css"; |
| 11 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 12 | table { border: none; } |
| 13 | |
| 14 | body { |
| 15 | font-size: 0.9em; |
| 16 | font-family: Geneva, Arial, Helvetica, sans-serif; |
| 17 | } |
| 18 | .heading { |
| 19 | font-weight: bold; |
| 20 | padding-bottom: 0.25em; |
| 21 | } |
| 22 | |
| 23 | #grid { |
| 24 | border: 1px solid #333; |
| 25 | width: 400px; |
| 26 | height: 500px; |
| 27 | } |
| 28 | </style> |
| 29 | <script type="text/javascript" |
| 30 | src="../../../dojo/dojo.js" |
| 31 | data-dojo-config="isDebug: true, parseOnLoad: true"> |
| 32 | </script> |
| 33 | <script type="text/javascript"> |
| 34 | dojo.require("doh.runner"); |
| 35 | |
| 36 | dojo.require("dojo.data.ItemFileReadStore"); |
| 37 | dojo.require("dojox.grid.DataGrid"); |
| 38 | dojo.require("dijit.form.TextBox"); |
| 39 | |
| 40 | dojo.declare("dojox.grid.formatterScopeObj", null, { |
| 41 | store: null, |
| 42 | _widgets: [], |
| 43 | constructor: function(kwArgs){ |
| 44 | this.store = kwArgs.store; |
| 45 | this._widgets = []; |
| 46 | }, |
| 47 | invalidateCache: function(){ |
| 48 | // Called when we need to clean our cache and destroy our |
| 49 | // widgets. |
| 50 | dojo.forEach(this._widgets, function(w){ |
| 51 | if(w && w.destroy){ |
| 52 | w.destroy(); |
| 53 | } |
| 54 | }); |
| 55 | this._widgets = []; |
| 56 | }, |
| 57 | fmtABBR: function(value, idx){ |
| 58 | if(value == "continent"){ |
| 59 | return "BIG"; |
| 60 | }else if(value == "country"){ |
| 61 | return "MID"; |
| 62 | }else if(value == "city"){ |
| 63 | return "SML"; |
| 64 | } |
| 65 | return "???"; |
| 66 | }, |
| 67 | fmtWidget: function(value, idx){ |
| 68 | if(!this._widgets[idx]){ |
| 69 | this._widgets[idx] = new dijit.form.TextBox({value: value, disabled: true}); |
| 70 | } |
| 71 | return this._widgets[idx]; |
| 72 | }, |
| 73 | fmtValue: function(value, idx){ |
| 74 | return value; |
| 75 | }, |
| 76 | fmtBool: function(value, idx){ |
| 77 | return (value == "country"); |
| 78 | }, |
| 79 | fmtInt: function(value, idx){ |
| 80 | return dojo.filter(["continent", "country", "city"], function(i){ return i == value; })[0]||null; |
| 81 | }, |
| 82 | fmtChildren: function(value, idx){ |
| 83 | return dojo.map(value, function(i){ |
| 84 | return this.store.getLabel(i); |
| 85 | }, this).join(", ") || " "; |
| 86 | }, |
| 87 | fmtItem: function(value, idx){ |
| 88 | if(!this.store.isItem(value)){ |
| 89 | return " "; |
| 90 | } |
| 91 | var d = new dojo.Deferred(); |
| 92 | var fx = function(items){ |
| 93 | if(items.length){ |
| 94 | d.callback(this.store.getLabel(items[0])) |
| 95 | }else{ |
| 96 | d.callback(" "); |
| 97 | } |
| 98 | }; |
| 99 | window.setTimeout(dojo.hitch(this, function(){ |
| 100 | this.store.fetch({query: {children: value}, onComplete: fx, onError: function(e){d.errback(e)}, scope: this}); |
| 101 | }), 5000); |
| 102 | return d; |
| 103 | } |
| 104 | }); |
| 105 | |
| 106 | dojo.addOnLoad(function(){ |
| 107 | // Connect our invalidateCache function to the "important" places |
| 108 | // so we get cleaned up correctly. |
| 109 | dojo.connect(grid, "_structureChanged", myObject, "invalidateCache"); |
| 110 | dojo.connect(grid, "_clearData", myObject, "invalidateCache"); |
| 111 | dojo.connect(grid, "destroy", myObject, "invalidateCache"); |
| 112 | |
| 113 | doh.register("tests", |
| 114 | [ |
| 115 | function test_gridFormatters(t){ |
| 116 | t.t(true); |
| 117 | } |
| 118 | ] |
| 119 | ); |
| 120 | doh.run(); |
| 121 | }); |
| 122 | </script> |
| 123 | <style> |
| 124 | .dijitTextBox { |
| 125 | color: gray; |
| 126 | width: 90px; |
| 127 | } |
| 128 | </style> |
| 129 | </head> |
| 130 | <body class="tundra"> |
| 131 | <h1 class="testTitle">Test: dojox.tests.grid.Grid Formatters</h1> |
| 132 | <div dojoType="dojo.data.ItemFileReadStore" data-dojo-id="readStore" url="support/countryStore.json?"></div> |
| 133 | <div dojoType="dojox.grid.formatterScopeObj" store="readStore" data-dojo-id="myObject"></div> |
| 134 | <table dojoType="dojox.grid.DataGrid" data-dojo-id="grid" formatterScope="myObject" |
| 135 | style="width: 65em;height: 25em;" store="readStore" queryOptions="{deep:true}" rowsPerPage="100"> |
| 136 | <thead> |
| 137 | <tr> |
| 138 | <th field="name" relWidth="2">Name</th> |
| 139 | <th field="type" relWidth="2">Type</th> |
| 140 | <th field="type" formatter="fmtABBR" relWidth="1">Abbr</th> |
| 141 | <th field="type" formatter="fmtValue" relWidth="2">Value</th> |
| 142 | <th field="type" formatter="fmtBool" relWidth="1">IsCountry</th> |
| 143 | <th field="type" formatter="fmtInt" relWidth="1">Int</th> |
| 144 | <th fields="children" formatter="fmtChildren" relWidth="3">Children</th> |
| 145 | <th field="_item" formatter="fmtItem" relWidth="2">Parent</th> |
| 146 | <th field="name" formatter="fmtWidget" relWidth="3">Widget</th> |
| 147 | </tr> |
| 148 | </thead> |
| 149 | </table> |
| 150 | </body> |
| 151 | </html> |