nnnjjj123
2020-11-17 1b2c1edb61190eeb19f465ff031eaa3b2a1b8dbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>GridFromHtml Tests</title>
        <meta name="viewport" content="width=570">
        <style>
            @import "../../dojo/resources/dojo.css";
            @import "../css/dgrid.css";
            @import "../css/skins/claro.css";
            body {
                padding: 0 80px; /* side padding to make it easier to scroll doc */
            }
 
            /* tests for renderCell / renderHeaderCell */
            .renderedCell {
                font-style: italic;
            }
            .renderedHeaderCell {
                text-decoration: underline;
            }
        </style>
        <script src="../../dojo/dojo.js"
            data-dojo-config="async: true"></script>
        <script>
            var store; // defined later, Memory store containing data
 
            function getOrdinal(num){
                // returns a String consisting of num + the appropriate ordinal suffix
                var ord = 'th';
                switch (num % 10) {
                    case 1:
                        ord = 'st';
                        break;
                    case 2:
                        ord = 'nd';
                        break;
                    case 3:
                        ord = 'rd';
                        break;
                }
                return num + ord;
            }
 
            function testFormatter(item){
                return "<h3>Step " + item.order + ": " + item.name + "</h3><p>" +
                    item.description + "</p>";
            }
 
            function testGet(item){
                return getOrdinal(item.order);
            }
 
            function testRenderHeaderCell(th){
                var div = document.createElement("div");
                div.className = "renderedHeaderCell";
                div.innerHTML = "Step";
                return div;
            }
 
            function testRenderCell(object, data, td, options){
                var div = document.createElement("div");
                div.className = "renderedCell";
                div.innerHTML = getOrdinal(object.order);
                return div;
            }
 
 
 
            require(["dgrid/GridFromHtml", "dgrid/OnDemandList",
                "dojo/_base/declare", "dgrid/test/data/createSyncStore", "dgrid/test/data/orderedData",
                "dojo/parser", "dojo/domReady!"],
            function(GridFromHtml, OnDemandList, declare, createSyncStore, orderedData, parser){
 
                window.gridFromHtmlLegacyFormatter = new GridFromHtml({},
                    "gridFromHtmlLegacyFormatter");
                gridFromHtmlLegacyFormatter.renderArray(orderedData.items);
 
                window.gridFromHtmlLegacyGet = new GridFromHtml({},
                    "gridFromHtmlLegacyGet");
                gridFromHtmlLegacyGet.renderArray(orderedData.items);
 
                window.gridFromHtmlNew = new GridFromHtml({},
                    "gridFromHtmlNew");
                gridFromHtmlNew.renderArray(orderedData.items);
 
                window.gridFromHtmlTestProps = new GridFromHtml({},
                    "gridFromHtmlTestProps");
                gridFromHtmlTestProps.renderArray(orderedData.items);
 
                // Need to expose GridFromHtml as a global for parser to find.
                // Mix in OnDemandList and create a store, since otherwise there's not
                // much of a way to add data.
                window.dgrid = { GridFromHtml: declare([GridFromHtml, OnDemandList]) };
                store = createSyncStore({data: orderedData});
                parser.parse();
            });
 
        </script>
    </head>
    <body class="claro">
 
        <p>Compare the outcome of the first group of tests with the first group in
            <a href="Grid_rendering.html">Grid_rendering.html</a>.</p>
        <!-- GridFromHtml should look for TRs with THs anywhere.
            Testing here with one thead, one tbody, and one implicit. -->
        <h2>1a: GridFromHtml with single column with formatter for _item field</h2>
        <table id="gridFromHtmlLegacyFormatter">
            <thead>
                <tr>
                    <th data-dgrid-column="{field:'_item', sortable:false, formatter:testFormatter}">Step</th>
                </tr>
            </thead>
        </table>
        <h2>1b: GridFromHtml with single column with get for order field, and blank label for 3rd column</h2>
        <table id="gridFromHtmlLegacyGet">
            <tbody>
                <tr>
                    <th data-dgrid-column="{field:'order', get:testGet}">Step</th>
                    <th>name</th>
                    <th data-dgrid-column="{label:'', field:'description', sortable:false}">what to do</th>
                </tr>
            </tbody>
        </table>
        <h2>1c: GridFromHtml with single column with renderCell function</h2>
        <p>(should look same as previous but with underlined first header cell
            and italicized first column values)</p>
        <table id="gridFromHtmlNew">
            <tr>
                <th data-dgrid-column="{field:'order',
                    renderCell:testRenderCell, renderHeaderCell:testRenderHeaderCell}">Step</th>
                <th>name</th>
                <th data-dgrid-column="{field:'description', sortable:false}">what to do</th>
            </tr>
        </table>
 
        <hr>
 
        <h2>2a: same as 1a, parsed from declarative markup (using a store)</h2>
        <table id="gridDeclarativeLegacyFormatter" data-dojo-id="gridDeclarativeLegacyFormatter"
            data-dojo-type="dgrid.GridFromHtml" data-dojo-props="collection: store">
            <thead>
                <tr>
                    <th data-dgrid-column="{field:'_item', sortable:false, formatter:testFormatter}">Step</th>
                </tr>
            </thead>
        </table>
        <h2>2b: same as 1b, parsed from declarative markup (using a store)</h2>
        <table id="gridDeclarativeLegacyGet" data-dojo-id="gridDeclarativeLegacyGet"
            data-dojo-type="dgrid.GridFromHtml" data-dojo-props="collection: store">
            <tbody>
                <tr>
                    <th data-dgrid-column="{field:'order', get:testGet}">Step</th>
                    <th>name</th>
                    <th data-dgrid-column="{field:'description', sortable:false}">what to do</th>
                </tr>
            </tbody>
        </table>
        <h2>2c: same as 1c, parsed from declarative markup (using a store)</h2>
        <table id="gridDeclarativeNew" data-dojo-id="gridDeclarativeNew"
            data-dojo-type="dgrid.GridFromHtml" data-dojo-props="collection: store">
            <tr>
                <th data-dgrid-column="{field:'order',
                    renderCell:testRenderCell, renderHeaderCell:testRenderHeaderCell}">Step</th>
                <th>name</th>
                <th data-dgrid-column="{field:'description', sortable:false}">what to do</th>
            </tr>
        </table>
 
        <hr>
 
        <h2>3a: Testing boolean property (un)specification in GridFromHtml</h2>
        <table id="gridFromHtmlTestProps">
            <thead>
                <tr>
                    <th rowspan="2" data-dgrid-column="{field:'name'}">No sortable attr (defaults to true)</th>
                    <th data-dgrid-column="{field:'name', sortable:false}">sortable="false"</th>
                </tr>
                <tr>
                    <th data-dgrid-column="{field:'name', sortable:true}">sortable="true"</th>
                </tr>
            </thead>
        </table>
 
    </body>
</html>