source: Dev/trunk/src/client/dojox/grid/tests/test_edit_canEdit.html

Last change on this file was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 4.4 KB
Line 
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=iso-8859-1" />
6        <title>Test dojox.grid.DataGrid Editing</title>
7        <style type="text/css">
8                @import "../resources/Grid.css";
9                body {
10                        font-family: Tahoma, Arial, Helvetica, sans-serif;
11                        font-size: 11px;
12                }
13                .dojoxGridRowEditing td {
14                        background-color: #F4FFF4;
15                }
16                .dojoxGrid input, .dojoxGrid select, .dojoxGrid textarea {
17                        margin: 0;
18                        padding: 0;
19                        border-style: none;
20                        width: 100%;
21                        font-size: 100%;
22                        font-family: inherit;
23                }
24                .dojoxGrid input { }
25                .dojoxGrid select { }
26                .dojoxGrid textarea { }
27                #controls {
28                        padding: 6px 0;
29                }
30                #grid {
31                        width: 850px;
32                        height: 350px;
33                        border: 1px solid silver;
34                }
35        </style>
36        <script type="text/javascript" src="../../../dojo/dojo.js"
37                data-dojo-config="isDebug:false, parseOnLoad: true"></script>
38        <script type="text/javascript">
39                dojo.require("dijit.dijit");
40                dojo.require("dojox.grid.DataGrid");
41                dojo.require("dojo.data.ItemFileWriteStore");
42                dojo.require("dojo.parser");
43        </script>
44        <script type="text/javascript" src="support/test_data.js"></script>
45        <script type="text/javascript">
46                // ==========================================================================
47                // Custom formatter
48                // ==========================================================================
49                formatMoney = function(inDatum) {
50                        return isNaN(inDatum) ? '...' : '$' + parseFloat(inDatum).toFixed(2);
51                }
52                // ==========================================================================
53                // Grid structure
54                // ==========================================================================
55                statusCell = { field: 'col3', name: 'Status', styles: 'text-align: center;', type: dojox.grid.cells.Select, options: [ "new", "read", "replied" ] };
56                gridLayout = [{
57                        defaultCell: { width: 8, editable: true, styles: 'text-align: right;'  },
58                        cells: [
59                                { name: 'Id', field: 'id', width: 3 },
60                                { name: 'Priority', field: 'col1', styles: 'text-align: center;', type: dojox.grid.cells.Select, options: ["Normal", "Note", "Important"], values: ["normal", "note", "important"]},
61                                { name: 'Mark', width: 3, field: 'col2', styles: 'text-align: center;', type: dojox.grid.cells.Bool },
62                                statusCell,
63                                { name: 'Message', field: 'col4', styles: '', width: '100%' },
64                                { name: 'Amount', field: 'col5', formatter: formatMoney },
65                                { name: 'Amount', field: 'col6', formatter: formatMoney }
66                        ]
67                },{
68                        defaultCell: { width: 4, editable: true, styles: 'text-align: right;' },
69                        rows: [
70                                { name: 'Mark', width: 3, field: 'col2', styles: 'text-align: center;', type: dojox.grid.cells.Bool},
71                                statusCell,
72                                { name: 'Amount', field: 'col5', formatter: formatMoney},
73                                { name: 'Detail', value: 'Detail'}
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                        });
90                }
91               
92                dojo.addOnLoad(function() {
93                        // simple canEdit logic
94                        grid.canEdit = function(inCell, inRowIndex){
95                                return (inCell.field &&
96                                                inCell.field != 'id' &&
97                                                !(inCell.field.charAt(3) > 1 && inCell.field.charAt(3) < 5)
98                                );
99                        }
100                });
101        </script>
102</head>
103<body>
104        <h2>
105                dojox.grid.DataGrid Basic Editing test
106        </h2>
107        <div id="controls">
108                <button onclick="grid.render()">Refresh</button>&nbsp;&nbsp;&nbsp;
109                <button onclick="grid.edit.focusEditor()">Focus Editor</button>
110                <button onclick="grid.focus.next()">Next Focus</button>&nbsp;&nbsp;&nbsp;
111                <button onclick="addRow()">Add Row</button>
112                <button onclick="grid.removeSelectedRows()">Remove</button>&nbsp;&nbsp;&nbsp;
113                <button onclick="grid.edit.apply()">Apply</button>
114                <button onclick="grid.edit.cancel()">Cancel</button>&nbsp;&nbsp;&nbsp;
115                <button onclick="grid.singleClickEdit = !grid.singleClickEdit">Toggle singleClickEdit</button>&nbsp;
116        </div>
117        <br />
118        <div id="grid" dojoType="dojox.grid.DataGrid"
119                data-dojo-id="grid"
120                rowSelector="20px"
121                store="test_store" structure="gridLayout"></div>
122        <br />
123        <div id="rowCount"></div>
124</body>
125</html>
Note: See TracBrowser for help on using the repository browser.