| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
| 2 | "http://www.w3.org/TR/html4/loose.dtd"> |
| 3 | <html dir="ltr"> |
| 4 | <head> |
| 5 | <title>Test Search plugin of dojox.grid.EnhancedGrid</title> |
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta> |
| 7 | <link rel=stylesheet href="support/common.css"/> |
| 8 | <style type="text/css"> |
| 9 | body { |
| 10 | font-size: 0.9em; |
| 11 | font-family: Geneva, Arial, Helvetica, sans-serif; |
| 12 | padding: 0.5em; |
| 13 | } |
| 14 | .title { |
| 15 | text-align:center; |
| 16 | margin:1em; |
| 17 | } |
| 18 | #grid{ |
| 19 | width: 90em; |
| 20 | height: 30em; |
| 21 | } |
| 22 | .outerdiv{ |
| 23 | position: relative; |
| 24 | height: 300px; |
| 25 | width: 300px; |
| 26 | background-color:blue; |
| 27 | } |
| 28 | .innerdiv{ |
| 29 | display:block; |
| 30 | position: absolute; |
| 31 | height: 100px; |
| 32 | width: 100px; |
| 33 | left: 50px; |
| 34 | top: 50px; |
| 35 | background-color:red; |
| 36 | } |
| 37 | .innerBtn{ |
| 38 | position: absolute; |
| 39 | height: 100px; |
| 40 | width: 100px; |
| 41 | right: 50px; |
| 42 | bottom: 50px; |
| 43 | background-color:yellow; |
| 44 | } |
| 45 | </style> |
| 46 | <script type="text/javascript" src="../../../../dojo/dojo.js" data-dojo-config="isDebug:true, parseOnLoad: true"></script> |
| 47 | <script type="text/javascript" src="../../../../dijit/tests/_testCommon.js"></script> |
| 48 | <script type="text/javascript"> |
| 49 | dojo.require("dojo.data.ItemFileWriteStore"); |
| 50 | dojo.require("dojox.grid.EnhancedGrid"); |
| 51 | dojo.require("dojox.grid.enhanced.plugins.Search"); |
| 52 | dojo.require("dojo.parser"); |
| 53 | |
| 54 | var layout = [{ |
| 55 | cells: [ |
| 56 | { field: "id", name:"Identity", datatype:"number", width: 4, editable: false}, |
| 57 | { field: "Genre", name:"Genre", datatype:"string", width: 10}, |
| 58 | { field: "Artist", name:"Artist", datatype:"string", width: 10}, |
| 59 | { field: "Year", name:"Year", datatype:"string", width: 2.5}, |
| 60 | { field: "Album", name:"Album", datatype:"string", width: 10}, |
| 61 | { field: "Name", name:"Name", datatype:"string", width: 8}, |
| 62 | { field: "Length", name:"Length", datatype:"string", width: 4}, |
| 63 | { field: "Track", name:"Track", datatype:"number", width: 3}, |
| 64 | { field: "Composer", name:"Composer", datatype:"string", width: 12}, |
| 65 | { field: "Download Date", name:"Download Date", datatype:"date", width: 12}, |
| 66 | { field: "Last Played", name:"Last Played", datatype:"time", width: 6}, |
| 67 | { field: "Heard", name: "Checked", datatype:"boolean", width: 6} |
| 68 | ] |
| 69 | }]; |
| 70 | var plugins = { |
| 71 | search: true |
| 72 | }; |
| 73 | var getInput = function(str){ |
| 74 | var start = str.indexOf('/'); |
| 75 | var end = str.lastIndexOf('/'); |
| 76 | if(start == 0 || end > 1){ |
| 77 | var regstr = str.substring(start + 1, end); |
| 78 | var modifiers = str.substring(end + 1, str.length); |
| 79 | str = new RegExp(regstr,modifiers); |
| 80 | } |
| 81 | console.log("input:", str); |
| 82 | return str; |
| 83 | }; |
| 84 | var onSearched = function(resultId, rowIdx){ |
| 85 | console.log("search result:", rowIdx); |
| 86 | if(rowIdx < 0){ |
| 87 | dojo.byId(resultId).innerHTML = "Not Found!"; |
| 88 | }else{ |
| 89 | dojo.byId(resultId).innerHTML = "Search result is Row " + (rowIdx + 1); |
| 90 | dijit.byId("grid").scrollToRow(rowIdx, true); |
| 91 | } |
| 92 | }; |
| 93 | var onSearch = function(){ |
| 94 | var args = {}; |
| 95 | dojo.query(".searchInput").forEach(function(input){ |
| 96 | var v = dojo.trim(input.value); |
| 97 | if(v){ |
| 98 | args[input.name] = getInput(v); |
| 99 | } |
| 100 | }); |
| 101 | console.log("search arguments:", args); |
| 102 | dijit.byId("grid").searchRow(args, dojo.partial(onSearched, "result2")); |
| 103 | }; |
| 104 | var onSearchAll = function(input){ |
| 105 | dijit.byId("grid").searchRow(getInput(input), dojo.partial(onSearched, "result1")); |
| 106 | }; |
| 107 | </script> |
| 108 | <script type="text/javascript" src="support/test_write_store_music.js"></script> |
| 109 | </head> |
| 110 | <body class="claro"> |
| 111 | <h1 class="title" tabindex="0" |
| 112 | onfocus="console.log('focus a'),this.style.color='red';" |
| 113 | onblur="console.log('blur a'),this.style.color='black';"> |
| 114 | dojox.grid.EnhancedGrid - Search</h1> |
| 115 | <div id="gridContainer"> |
| 116 | <div id="grid" dojoType="dojox.grid.EnhancedGrid" store="test_store[0]" structure="layout" plugins="plugins"></div> |
| 117 | </div><br/> |
| 118 | <br /> |
| 119 | Note: Use "/.../" for Regular Expressions. Wildcards (* and ?) are available when not using "/.../". |
| 120 | <hr /> |
| 121 | <div>Search all columns for<input id="allcolumnsInput" type="text" size="30" value="/void/i" /> |
| 122 | <button onclick="onSearchAll(dojo.byId('allcolumnsInput').value)">Go =></button> |
| 123 | <span id="result1"></span> |
| 124 | <hr /> |
| 125 | Search with a query object (extends the functionality of the standard store query). |
| 126 | <table> |
| 127 | <thead> |
| 128 | <tr> |
| 129 | <th>Column</th> |
| 130 | <th>Query String or Regular Expression</th> |
| 131 | <th></th> |
| 132 | </tr> |
| 133 | </thead> |
| 134 | <tbody> |
| 135 | <tr> |
| 136 | <td>id</td> |
| 137 | <td><input name="id" class="searchInput" type="text" size="30" /></td> |
| 138 | <td rowspan="11" align="center" valign="center" style="padding-left: 50px;"> |
| 139 | <button onclick="onSearch()">Search =></button> |
| 140 | <span id="result2"></span> |
| 141 | </td> |
| 142 | </tr> |
| 143 | <tr> |
| 144 | <td>Genre</td> |
| 145 | <td><input name="Genre" class="searchInput" type="text" size="30" /></td> |
| 146 | </tr> |
| 147 | <tr> |
| 148 | <td>Artist</td> |
| 149 | <td><input name="Artist" class="searchInput" type="text" size="30" value="/an/i" /></td> |
| 150 | </tr> |
| 151 | <tr> |
| 152 | <td>Year</td> |
| 153 | <td><input name="Year" class="searchInput" type="text" size="30" /></td> |
| 154 | </tr> |
| 155 | <tr> |
| 156 | <td>Album</td> |
| 157 | <td><input name="Album" class="searchInput" type="text" size="30" value="/t.*t/i" /></td> |
| 158 | </tr> |
| 159 | <tr> |
| 160 | <td>Name</td> |
| 161 | <td><input name="Name" class="searchInput" type="text" size="30" /></td> |
| 162 | </tr> |
| 163 | <tr> |
| 164 | <td>Length</td> |
| 165 | <td><input name="Length" class="searchInput" type="text" size="30" /></td> |
| 166 | </tr> |
| 167 | <tr> |
| 168 | <td>Track</td> |
| 169 | <td><input name="Track" class="searchInput" type="text" size="30" /></td> |
| 170 | </tr> |
| 171 | <tr> |
| 172 | <td>Composer</td> |
| 173 | <td><input name="Composer" class="searchInput" type="text" size="30" value="*ss*" /></td> |
| 174 | </tr> |
| 175 | <tr> |
| 176 | <td>Download Date</td> |
| 177 | <td><input name="Download Date" class="searchInput" type="text" size="30" /></td> |
| 178 | </tr> |
| 179 | <tr> |
| 180 | <td>Last Played</td> |
| 181 | <td><input name="Last Played" class="searchInput" type="text" size="30" /></td> |
| 182 | </tr> |
| 183 | </tbody> |
| 184 | </table> |
| 185 | <p><strong>Note:</strong> To see the tundra theme, just append <b style="color:blue;">?theme=tundra</b> to the URL.</p> |
| 186 | </body> |
| 187 | </html> |