Changeset 13845
- Timestamp:
- 05/30/08 15:51:43 (6 months ago)
- Location:
- dojox/trunk/grid
- Files:
-
- 1 added
- 4 modified
-
DataGrid.js (modified) (10 diffs)
-
DataSelection.js (added)
-
Selection.js (modified) (2 diffs)
-
tests/test_yahoo_search.html (modified) (4 diffs)
-
_Grid.js (modified) (36 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dojox/trunk/grid/DataGrid.js
r13832 r13845 2 2 3 3 dojo.require("dojox.grid._Grid"); 4 dojo.require("dojox.grid.DataSelection"); 4 5 5 6 dojo.declare("dojox.grid.DataGrid", dojox.grid._Grid, { … … 30 31 }, 31 32 33 createSelection: function(){ 34 this.selection = new dojox.grid.DataSelection(this); 35 }, 36 32 37 get: function(inItem, inRowIndex){ 33 38 return (!inItem ? this.defaultValue : (!this.field ? this.value : this.grid.store.getValue(inItem, this.field))); … … 72 77 this._refresh(); 73 78 }, 74 79 75 80 _setStore: function(store){ 76 81 if(this.store&&this._store_connects){ … … 86 91 87 92 this._canEdit = !!f["dojo.data.api.Write"]; 88 93 89 94 if(!!f["dojo.data.api.Notification"]){ 90 95 h.push(this.connect(this.store, "onSet", "_onSet")); … … 149 154 150 155 _clearData: function(){ 156 this.rowCount = 0; 151 157 this._identity_map = {}; 152 158 this._pages = []; … … 176 182 }, 177 183 178 filter: function(query ){184 filter: function(query, reRender){ 179 185 this.query = query; 180 this._fetch(0, false); 186 if(reRender){ 187 this._clearData(); 188 } 189 this._fetch(); 181 190 }, 182 191 … … 348 357 // so it's no big deal, but it's something to be aware of. 349 358 // * I'm pretty sure that colgroup introspection is missing some of 350 // the available settable properties. 359 // the available settable properties. 351 360 // * No handling of cell formatting and content getting is done 352 361 var d = dojo; … … 361 370 // if a structure isn't referenced, do we have enough 362 371 // data to try to build one automatically? 363 if( !props.structure && 372 if( !props.structure && 364 373 node.nodeName.toLowerCase() == "table"){ 365 374 … … 367 376 props.structure = d.query("> colgroup", node).map(function(cg){ 368 377 var sv = d.attr(cg, "span"); 369 var v = { 378 var v = { 370 379 noscroll: (d.attr(cg, "noscroll") == "true") ? true : false, 371 380 __span: (!!sv ? parseInt(sv) : 1), … … 381 390 __span: Infinity, 382 391 cells: [] // catch-all view 383 }); 392 }); 384 393 } 385 394 // check to see if we're gonna have more than one view 386 395 387 396 // for each tr in our th, create a row of cells 388 397 d.query("thead > tr", node).forEach(function(tr, tr_idx){ -
dojox/trunk/grid/Selection.js
r13588 r13845 3 3 dojo.declare("dojox.grid.Selection", null, { 4 4 // summary: 5 // Manages row selection for grid. Owned by grid and used internally 5 // Manages row selection for grid. Owned by grid and used internally 6 6 // for selection. Override to implement custom selection. 7 7 … … 10 10 this.selected = []; 11 11 }, 12 12 13 13 multiSelect: true, 14 14 selected: null, -
dojox/trunk/grid/tests/test_yahoo_search.html
r13832 r13845 21 21 <script type="text/javascript"> 22 22 dojo.require("dojox.grid.DataGrid"); 23 dojo.require("dojo.io.script"); 24 dojo.require("dojox.rpc.Service"); 25 dojo.require("dojox.data.ServiceStore"); 23 26 dojo.require("dojo.parser"); 24 27 </script> 25 <script type="text/javascript" src="yahooSearch.js"></script>26 28 <script type="text/javascript"> 27 webFields = [ 28 { name: 'Title', na: '' }, 29 { name: 'ModificationDate', na: ''}, 30 { name: 'Summary', na: ' ' }, 31 { name: 'Url', na: '' }, 32 { name: 'MimeType', na: ' '}, 33 { name: 'DisplayUrl', na: ' '} 34 ]; 35 36 imageFields = [ 37 { name: 'Title', na: '' }, 38 { name: 'Thumbnail', na: ''}, 39 { name: 'Summary', na: '' }, 40 { name: 'Url', na: '' }, 41 { name: 'FileSize', na: ''}, 42 { name: 'Height', na: ''}, 43 { name: 'Width', na: ''} 44 ]; 45 46 var model = new dojox.grid._data.yahooSearch(imageFields, null, "searchInput"); 47 model.observer(this); 48 // report some model send/receive status 49 model.onSend = function(inParams) { 50 dojo.byId('sendInfo').innerHTML = dojo.string.substitute('Request rows ${0} to ${1}.  ', [inParams.start, inParams.start + inParams.results -1] ); 51 } 52 model.onReceive = function(inData) { 53 dojo.byId('receiveInfo').innerHTML = dojo.string.substitute('Receive rows ${0} to ${1}.  ', [inData.firstResultPosition, inData.firstResultPosition + inData.totalResultsReturned-1]); 54 } 55 56 29 dojo.declare("YahooStore", dojox.data.ServiceStore, { 30 _processResults: function(results, def){ 31 var totalCount = 0; 32 if(results.ResultSet){ 33 totalCount = results.ResultSet.totalResultsAvailable; 34 results = results.ResultSet.Result; 35 } 36 var resultSet = this.inherited(arguments); 37 resultSet.totalCount = totalCount > 1000 ? 1000 : totalCount; 38 return resultSet; 39 }, 40 fetch: function(request){ 41 if(request.query){ 42 if(request.count){ 43 request.query['results'] = request.count; 44 } 45 if(typeof request.start != "undefined"){ 46 request.query['start'] = request.start + 1; 47 } 48 } 49 50 return this.inherited(arguments); 51 } 52 }); 53 var service = new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.SMDLibrary", "yahoo.smd")); 54 var store = new YahooStore({ service: service.webSearch }); 55 56 var getCellData = function(item, field){ 57 return grid.store.getValue(item, field); 58 } 59 60 var getLink = function(inItem, inRowIndex){ 61 if(!inItem){ return ' '; } 62 var text = getCellData(inItem, 'Title'); 63 var link = getCellData(inItem, 'ClickUrl'); 64 return dojo.string.substitute( 65 '<a target="_blank" href="${href}">${text}</a>', 66 { href: link, text: text } 67 ); 68 }; 69 70 var formatDate = function(inDatum, inRowIndex){ 71 if(!inDatum){ return ' '; } 72 var d = new Date(inDatum * 1000); 73 return dojo.string.substitute( 74 "${0}/${1}/${2}", 75 [ d.getMonth()+1, d.getDate(), d.getFullYear() ] 76 ); 77 }; 78 79 var getImage = function(inItem, inRowIndex){ 80 if(!inItem){ return ' '; } 81 var thumb = getCellData(inItem, "Thumbnail"); 82 var o = { 83 href: getCellData(inItem, "ClickUrl"), 84 src: thumb.Url, 85 width: thumb.Width, 86 height: thumb.Height 87 } 88 return dojo.string.substitute( 89 '<a href="${href}" target="_blank"><img border=0 src="${src}" width="${width}" height="${height}"></a>', o); 90 }; 91 92 93 var getDimensions = function(inItem, inRowIndex){ 94 if(!inItem){ return ' '; } 95 var w = getCellData(inItem, "Width"); 96 var h = getCellData(inItem, "Height"); 97 return w + ' x ' + h; 98 } 99 57 100 var webLayout = [ 58 { type: 'dojox.grid._RowSelector', width: '20px' },59 {noscroll: true,101 { 102 noscroll: true, 60 103 cells: [ 61 [ { name: 'Row', width: 3, styles: 'text-align: center;', get: function(inRowIndex) { return inRowIndex + 1 } }] 104 { 105 name: 'Row', 106 width: 3, 107 styles: 'text-align: center;', 108 get: function(inItem, inRowIndex) { return inRowIndex + 1 } 109 } 62 110 ] 63 111 }, 64 { cells: [ 65 [ { name: 'Site', width: 30, field: 3, extraField: 0, formatter: formatLink }, { name: 'Date', width: 10, field: 1, formatter: formatDate} ], 66 [ { name: 'Display Url', width: 30, field: 5, styles: 'color: green; size: small;' }, { name: 'Type', width: 10, field: 4, styles: ' font-style: italic; color: gray; size: small;'} ], 67 [ { name: 'Summary', width: 40, colSpan: 2, field: 2 } ] 68 ]} 112 [ 113 [ 114 { name: 'Site', width: 30, field: 'ClickUrl', get: getLink }, 115 { name: 'Date', width: 10, field: 'ModificationDate', formatter: formatDate} 116 ],[ 117 { name: 'Display Url', width: 30, field: 'Url', styles: 'color: green; size: small;' }, 118 { name: 'Type', width: 10, field: 'MimeType', styles: ' font-style: italic; color: gray; size: small;'} 119 ],[ 120 { name: 'Summary', width: 40, colSpan: 2, field: 'Summary' } 121 ] 122 ] 69 123 ]; 70 124 … … 76 130 77 131 var imageLayout = [ 78 { type: 'dojox.grid._RowSelector', width: '20px' },79 {noscroll: true,132 { 133 noscroll: true, 80 134 cells: [ 81 [ { name: 'Row', width: 3, styles: 'text-align: center;', get: function(inRowIndex) { return inRowIndex + 1 } }] 135 { 136 name: 'Row', 137 width: 3, 138 styles: 'text-align: center;', 139 get: function(inItem, inRowIndex) { return inRowIndex + 1 } 140 } 82 141 ] 83 142 }, 84 { onBeforeRow: beforeImageRow, 143 { 144 onBeforeRow: beforeImageRow, 85 145 cells: [ 86 [ { name: 'Image', cellStyles: "height: 100px;", styles: "text-align: center;", width: 13, rowSpan: 2, field: 3, extraField: 1, formatter: formatImage }, 87 { name: 'Title', cellStyles: "height: 10px;", width: 14, field: 3, extraField: 0, formatter: formatLink }, 88 { name: 'Size', width: 8, field: 4, styles: "font-style: italic; text-align: center;" }, 89 { name: 'Dimensions', width: 8, field: 6, extraField: 5, styles: "text-align: center;", formatter: formatDimensions } 146 [ 147 { name: 'Image', cellStyles: "height: 100px;", styles: "text-align: center;", width: 13, rowSpan: 2, field: 'Url', get: getImage }, 148 { name: 'Title', cellStyles: "height: 10px;", width: 14, field: 'Title', get: getLink }, 149 { name: 'Size', width: 8, field: 'FileSize', styles: "font-style: italic; text-align: center;" }, 150 { name: 'Dimensions', width: 8, styles: "text-align: center;", get: getDimensions } 90 151 ], 91 [ { name: 'Summary', cellStyles: "vertical-align: top; height: 75px;", colSpan: 3, field: 2 } ] 92 ]} 152 [ 153 { name: 'Summary', cellStyles: "vertical-align: top; height: 75px;", colSpan: 3, field: 'Summary' } 154 ] 155 ] 156 } 93 157 ]; 94 158 95 159 // execute search 160 var lastLayoutType = webLayout; 96 161 doSearch = function() { 162 var value = dojo.byId("searchInput").value; 97 163 var web = dojo.byId('webRb').checked; 98 model.setRowCount(0); 99 model.clear(); 100 model.fields.set(web ? webFields : imageFields); 101 model.url = 'http://search.yahooapis.com/' + (web ? 'WebSearchService/V1/webSearch' : 'ImageSearchService/V1/imageSearch'); 102 grid.scrollToRow(0); 103 grid.setStructure(web ? webLayout : imageLayout); 104 model.requestRows(); 164 store.service = (web ? service.webSearch : service.imageSearch); 165 if(lastLayoutType != (web ? webLayout : imageLayout)){ 166 grid.setStructure(web ? webLayout : imageLayout); 167 } 168 grid.filter({ query: value }, true); 105 169 } 106 170 … … 114 178 dojo.byId('webRb').checked = "checked"; 115 179 dojo.connect(dojo.byId("searchInput"), "keypress", keypress); 116 doSearch();117 180 }); 118 181 … … 127 190 <input id="searchInput" type="text" value="apple"> 128 191 <button onclick="doSearch()">Search</button><br><br> 129 <div jsId="grid" class="grid" autoWidth="true" structure="webLayout" dojoType="dojox.grid.Grid" store="model" elasticView="1"></div>192 <div id="grid" jsId="grid" class="grid" autoWidth="true" structure="webLayout" dojoType="dojox.grid.DataGrid" store="store" elasticView="1" query="{ query: 'apple' }" rowSelector="20px"></div> 130 193 <br> 131 194 <div id="info"> -
dojox/trunk/grid/_Grid.js
r13826 r13845 38 38 }; 39 39 40 dojo.declare('dojox.grid._Grid', 41 [ dijit._Widget, dijit._Templated, dojox.grid._Events ], 40 dojo.declare('dojox.grid._Grid', 41 [ dijit._Widget, dijit._Templated, dojox.grid._Events ], 42 42 { 43 43 // summary: … … 57 57 // example: 58 58 // A quick sample: 59 // 59 // 60 60 // define a get function 61 61 // | function get(inRowIndex){ // called in cell context 62 62 // | return [this.index, inRowIndex].join(', '); 63 63 // | } 64 // 64 // 65 65 // define the grid structure: 66 66 // | var structure = [ // array of view objects 67 67 // | { cells: [// array of rows, a row is an array of cells 68 68 // | [ 69 // | { name: "Alpha", width: 6 }, 70 // | { name: "Beta" }, 69 // | { name: "Alpha", width: 6 }, 70 // | { name: "Beta" }, 71 71 // | { name: "Gamma", get: get }] 72 72 // | ]} 73 73 // | ]; 74 // 75 // | <div id="grid" 76 // | rowCount="100" get="get" 77 // | structure="structure" 74 // 75 // | <div id="grid" 76 // | rowCount="100" get="get" 77 // | structure="structure" 78 78 // | dojoType="dojox.grid._Grid"></div> 79 79 80 80 templatePath: dojo.moduleUrl("dojox.grid","resources/_Grid.html"), 81 81 82 82 // classTag: String 83 83 // CSS class applied to the grid's domNode … … 85 85 86 86 get: function(inRowIndex){ 87 // summary: Default data getter. 87 // summary: Default data getter. 88 88 // description: 89 89 // Provides data to display in a grid cell. Called in grid cell context. … … 94 94 // Data to display for a given grid cell. 95 95 }, 96 96 97 97 // settings 98 98 // rowCount: Integer 99 // Number of rows to display. 99 // Number of rows to display. 100 100 rowCount: 5, 101 101 … … 103 103 // Number of rows to keep in the rendering cache. 104 104 keepRows: 75, 105 105 106 106 // rowsPerPage: Integer 107 107 // Number of rows to render at a time. … … 111 111 // If autoWidth is true, grid width is automatically set to fit the data. 112 112 autoWidth: false, 113 113 114 114 // autoHeight: Boolean 115 115 // If autoHeight is true, grid height is automatically set to fit the data. 116 116 autoHeight: false, 117 117 118 118 // autoRender: Boolean 119 119 // If autoRender is true, grid will render itself after initialization. … … 131 131 // Override defaults and make the indexed grid view elastic, thus filling available horizontal space. 132 132 elasticView: -1, 133 133 134 134 // singleClickEdit: boolean 135 135 // Single-click starts editing. Default is double-click … … 143 143 // Used to store the last two clicks, to ensure double-clicking occurs based on the intended row 144 144 _click: null, 145 145 146 146 // private 147 147 sortInfo: 0, … … 162 162 this.createViews(); 163 163 this.createManagers(); 164 this.createSelection(); 164 165 dojox.html.metrics.initOnFontResize(); 165 166 this.connect(dojox.html.metrics, "onFontResize", "textSizeChanged"); … … 173 174 this._click = []; 174 175 }, 175 176 176 177 destroy: function(){ 177 178 this.domNode.onReveal = null; … … 181 182 dijit._Widget.prototype.destroy.apply(this, arguments); 182 183 }, 183 184 184 185 styleChanged: function(){ 185 186 this.setStyledClass(this.domNode, ''); 186 187 }, 187 188 188 189 _styleChanged: function(){ 189 190 this.styleChanged(); 190 191 this.update(); 191 192 }, 192 193 193 194 textSizeChanged: function(){ 194 195 setTimeout(dojo.hitch(this, "_textSizeChanged"), 1); 195 196 }, 196 197 197 198 _textSizeChanged: function(){ 198 199 if(this.domNode){ … … 203 204 } 204 205 }, 205 206 206 207 sizeChange: function(){ 207 208 jobs.job(this.id + 'SizeChange', 50, dojo.hitch(this, "update")); 208 209 }, 209 210 210 211 renderOnIdle: function() { 211 212 setTimeout(dojo.hitch(this, "render"), 1); 212 213 }, 213 214 214 215 createManagers: function(){ 215 216 // summary: 216 217 // create grid managers for various tasks including rows, focus, selection, editing 217 218 218 219 // row manager 219 220 this.rows = new dojox.grid._RowManager(this); 220 221 // focus manager 221 222 this.focus = new dojox.grid._FocusManager(this); 223 // edit manager 224 this.edit = new dojox.grid._EditManager(this); 225 }, 226 227 createSelection: function(){ 222 228 // selection manager 223 229 this.selection = new dojox.grid.Selection(this); 224 // edit manager225 this.edit = new dojox.grid._EditManager(this);226 230 }, 227 231 … … 244 248 this.views.createView = dojo.hitch(this, "createView"); 245 249 }, 246 250 247 251 createView: function(inClass){ 248 252 var c = dojo.getObject(inClass);