| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 6 | <title>Test dojox.grid.Grid Editing</title> |
| 7 | <style type="text/css"> |
| 8 | @import "../resources/Grid.css"; |
| 9 | @import "../resources/tundraGrid.css"; |
| 10 | @import "../../../dojo/resources/dojo.css"; |
| 11 | @import "../../../dijit/themes/tundra/tundra.css"; |
| 12 | @import "../../../dijit/themes/tundra/tundra_rtl.css"; |
| 13 | @import "../../../dijit/tests/css/dijitTests.css"; |
| 14 | #controls button { |
| 15 | margin-left: 10px; |
| 16 | } |
| 17 | #grid { |
| 18 | width: 850px; |
| 19 | height: 350px; |
| 20 | border: 1px solid silver; |
| 21 | } |
| 22 | </style> |
| 23 | <script type="text/javascript" src="../../../dojo/dojo.js" |
| 24 | data-dojo-config="isDebug: true, parseOnLoad: true"></script> |
| 25 | |
| 26 | <script type="text/javascript"> |
| 27 | dojo.require("dijit.dijit"); |
| 28 | dojo.require("dojox.grid.DataGrid"); |
| 29 | dojo.require("dojox.grid.cells.dijit"); |
| 30 | dojo.require("dojo.data.ItemFileWriteStore"); |
| 31 | dojo.require("dojo.parser"); |
| 32 | </script> |
| 33 | <script type="text/javascript" src="support/test_data_date.js"></script> |
| 34 | <script type="text/javascript"> |
| 35 | // ========================================================================== |
| 36 | // Custom formatters |
| 37 | // ========================================================================== |
| 38 | formatCurrency = function(inDatum){ |
| 39 | return isNaN(inDatum) ? '...' : dojo.currency.format(inDatum, this.constraint); |
| 40 | } |
| 41 | formatDate = function(inDatum){ |
| 42 | return dojo.date.locale.format(new Date(inDatum), this.constraint); |
| 43 | } |
| 44 | // ========================================================================== |
| 45 | // Grid structure |
| 46 | // ========================================================================== |
| 47 | statusCell = { |
| 48 | field: 'col3', name: 'Status', |
| 49 | styles: 'text-align: center;', |
| 50 | type: dojox.grid.cells.Select, |
| 51 | options: [ "new", "read", "replied" ] |
| 52 | }; |
| 53 | |
| 54 | gridLayout = [{ |
| 55 | defaultCell: { width: 8, editable: true, type: dojox.grid.cells._Widget, styles: 'text-align: right;' }, |
| 56 | rows: [ |
| 57 | { name: 'Id', field: 'id', editable: false /* Can't edit ID's of dojo.data items */ }, |
| 58 | { name: 'Date', field: 'col8', width: 10, |
| 59 | type: dojox.grid.cells.DateTextBox, |
| 60 | formatter: formatDate, |
| 61 | constraint: {formatLength: 'long', selector: "date"}}, |
| 62 | { name: 'Priority', styles: 'text-align: center;', field: 'col1', |
| 63 | type: dojox.grid.cells.ComboBox, |
| 64 | options: ["normal", "note", "important"], width: 10}, |
| 65 | { name: 'Mark', field: 'col2', width: 3, styles: 'text-align: center;', |
| 66 | type: dojox.grid.cells.CheckBox}, |
| 67 | statusCell, |
| 68 | { name: 'Message', field: 'col4', styles: '', width: 10, |
| 69 | type: dojox.grid.cells.Editor, editorToolbar: true }, |
| 70 | { name: 'Amount', field: 'col5', formatter: formatCurrency, constraint: {currency: 'EUR'}, |
| 71 | widgetClass: dijit.form.CurrencyTextBox }, |
| 72 | { name: 'Amount', field: 'col5', formatter: formatCurrency, constraint: {currency: 'EUR'}, |
| 73 | widgetClass: dijit.form.HorizontalSlider, width: 10} |
| 74 | ] |
| 75 | }]; |
| 76 | // ========================================================================== |
| 77 | // UI Action |
| 78 | // ========================================================================== |
| 79 | addRow = function(){ |
| 80 | test_store.newItem({ |
| 81 | id: grid.rowCount, |
| 82 | col1: 'normal', |
| 83 | col2: false, |
| 84 | col3: 'new', |
| 85 | col4: 'Now is the time for all good men to come to the aid of their party.', |
| 86 | col5: 99.99, |
| 87 | col6: 9.99, |
| 88 | col7: false, |
| 89 | col8: new Date() |
| 90 | }); |
| 91 | } |
| 92 | </script> |
| 93 | </head> |
| 94 | <body class="tundra"> |
| 95 | <h1>dojox.grid.DataGrid Basic Editing test</h1> |
| 96 | <br /> |
| 97 | <div id="controls"> |
| 98 | <button onclick="grid.render()">Refresh</button> |
| 99 | <button onclick="grid.edit.focusEditor()">Focus Editor</button> |
| 100 | <button onclick="grid.focus.next()">Next Focus</button> |
| 101 | <button onclick="addRow()">Add Row</button> |
| 102 | <button onclick="grid.removeSelectedRows()">Remove</button> |
| 103 | <button onclick="grid.edit.apply()">Apply</button> |
| 104 | <button onclick="grid.edit.cancel()">Cancel</button> |
| 105 | <button onclick="grid.singleClickEdit = !grid.singleClickEdit">Toggle singleClickEdit</button> |
| 106 | </div> |
| 107 | <br /> |
| 108 | <div id="grid" data-dojo-id="grid" dojoType="dojox.grid.DataGrid" store="test_store" rowSelector="20px" structure="gridLayout" escapeHTMLInData="false"></div> |
| 109 | <br /> |
| 110 | <div id="rowCount"></div> |
| 111 | </body> |
| 112 | </html> |