1 |
// DATA_TEMPLATE: empty_table |
2 |
oTest.fnStart( "6872 - mDataProp and sDefaultContent for deep objects" ); |
3 |
|
4 |
$(document).ready( function () { |
5 |
var test = false; |
6 |
|
7 |
$.fn.dataTable.ext.sErrMode = "throw"; |
8 |
|
9 |
|
10 |
|
11 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
12 |
* Shallow properties |
13 |
*/ |
14 |
|
15 |
$('#example').dataTable( { |
16 |
"aaData": [ |
17 |
{ |
18 |
"a": "a", |
19 |
"b": "b", |
20 |
"c": "c", |
21 |
"d": "d", |
22 |
"e": "e" |
23 |
} |
24 |
], |
25 |
"aoColumns": [ |
26 |
{ "mDataProp": "a" }, |
27 |
{ "mDataProp": "b" }, |
28 |
{ "mDataProp": "c" }, |
29 |
{ "mDataProp": "d" }, |
30 |
{ "mDataProp": "e" } |
31 |
] |
32 |
} ); |
33 |
|
34 |
oTest.fnTest( |
35 |
"Basic initialisation of objects works", |
36 |
null, |
37 |
function () { return $('#example tbody td:eq(0)').html() === "a"; } |
38 |
); |
39 |
|
40 |
oTest.fnTest( |
41 |
"Error when property missing (no default content)", |
42 |
function () { |
43 |
oSession.fnRestore(); |
44 |
test = false; |
45 |
|
46 |
try { |
47 |
$('#example').dataTable( { |
48 |
"aaData": [ |
49 |
{ |
50 |
"a": "a", |
51 |
"b": "b", |
52 |
"d": "d", |
53 |
"e": "e" |
54 |
} |
55 |
], |
56 |
"aoColumns": [ |
57 |
{ "mDataProp": "a" }, |
58 |
{ "mDataProp": "b" }, |
59 |
{ "mDataProp": "c" }, |
60 |
{ "mDataProp": "d" }, |
61 |
{ "mDataProp": "e" } |
62 |
] |
63 |
} ); |
64 |
} catch (e) { |
65 |
test = true; |
66 |
} |
67 |
}, |
68 |
function () { return test; } |
69 |
); |
70 |
|
71 |
oTest.fnTest( |
72 |
"Default content used for missing prop and no error", |
73 |
function () { |
74 |
oSession.fnRestore(); |
75 |
|
76 |
$('#example').dataTable( { |
77 |
"aaData": [ |
78 |
{ |
79 |
"a": "a", |
80 |
"b": "b", |
81 |
"d": "d", |
82 |
"e": "e" |
83 |
} |
84 |
], |
85 |
"aoColumns": [ |
86 |
{ "mDataProp": "a" }, |
87 |
{ "mDataProp": "b" }, |
88 |
{ "mDataProp": "c", "sDefaultContent": "test" }, |
89 |
{ "mDataProp": "d" }, |
90 |
{ "mDataProp": "e" } |
91 |
] |
92 |
} ); |
93 |
}, |
94 |
function () { return $('#example tbody td:eq(2)').html() === "test"; } |
95 |
); |
96 |
|
97 |
|
98 |
|
99 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
100 |
* Deep properties with a single object |
101 |
*/ |
102 |
|
103 |
oTest.fnTest( |
104 |
"Basic test with deep properties", |
105 |
function () { |
106 |
oSession.fnRestore(); |
107 |
|
108 |
$('#example').dataTable( { |
109 |
"aaData": [ |
110 |
{ |
111 |
"z": { |
112 |
"a": "a", |
113 |
"b": "b", |
114 |
"c": "c", |
115 |
"d": "d", |
116 |
"e": "e" |
117 |
} |
118 |
} |
119 |
], |
120 |
"aoColumns": [ |
121 |
{ "mDataProp": "z.a" }, |
122 |
{ "mDataProp": "z.b" }, |
123 |
{ "mDataProp": "z.c" }, |
124 |
{ "mDataProp": "z.d" }, |
125 |
{ "mDataProp": "z.e" } |
126 |
] |
127 |
} ); |
128 |
}, |
129 |
function () { return $('#example tbody td:eq(0)').html() === "a"; } |
130 |
); |
131 |
|
132 |
oTest.fnTest( |
133 |
"Error when property missing on deep get (no default content)", |
134 |
function () { |
135 |
oSession.fnRestore(); |
136 |
test = false; |
137 |
|
138 |
try { |
139 |
$('#example').dataTable( { |
140 |
"aaData": [ |
141 |
{ |
142 |
"z": { |
143 |
"a": "a", |
144 |
"b": "b", |
145 |
"c": "c", |
146 |
"e": "e" |
147 |
} |
148 |
} |
149 |
], |
150 |
"aoColumns": [ |
151 |
{ "mDataProp": "z.a" }, |
152 |
{ "mDataProp": "z.b" }, |
153 |
{ "mDataProp": "z.c" }, |
154 |
{ "mDataProp": "z.d" }, |
155 |
{ "mDataProp": "z.e" } |
156 |
] |
157 |
} ); |
158 |
} catch (e) { |
159 |
test = true; |
160 |
} |
161 |
}, |
162 |
function () { return test; } |
163 |
); |
164 |
|
165 |
oTest.fnTest( |
166 |
"Default content used for missing prop on deep get and no error", |
167 |
function () { |
168 |
oSession.fnRestore(); |
169 |
|
170 |
$('#example').dataTable( { |
171 |
"aaData": [ |
172 |
{ |
173 |
"z": { |
174 |
"a": "a", |
175 |
"b": "b", |
176 |
"c": "c", |
177 |
"e": "e" |
178 |
} |
179 |
} |
180 |
], |
181 |
"aoColumns": [ |
182 |
{ "mDataProp": "z.a" }, |
183 |
{ "mDataProp": "z.b" }, |
184 |
{ "mDataProp": "z.c" }, |
185 |
{ "mDataProp": "z.d", "sDefaultContent": "test" }, |
186 |
{ "mDataProp": "z.e" } |
187 |
] |
188 |
} ); |
189 |
}, |
190 |
function () { return $('#example tbody td:eq(3)').html() === "test"; } |
191 |
); |
192 |
|
193 |
|
194 |
|
195 |
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
196 |
* Deep properties with individual objects |
197 |
*/ |
198 |
|
199 |
oTest.fnTest( |
200 |
"Basic test with deep individual properties", |
201 |
function () { |
202 |
oSession.fnRestore(); |
203 |
|
204 |
$('#example').dataTable( { |
205 |
"aaData": [ |
206 |
{ |
207 |
"m": { "a": "a" }, |
208 |
"n": { "b": "b" }, |
209 |
"o": { "c": "c" }, |
210 |
"p": { "d": "d" }, |
211 |
"q": { "e": "e" } |
212 |
} |
213 |
], |
214 |
"aoColumns": [ |
215 |
{ "mDataProp": "m.a" }, |
216 |
{ "mDataProp": "n.b" }, |
217 |
{ "mDataProp": "o.c" }, |
218 |
{ "mDataProp": "p.d" }, |
219 |
{ "mDataProp": "q.e" } |
220 |
] |
221 |
} ); |
222 |
}, |
223 |
function () { return $('#example tbody td:eq(0)').html() === "a"; } |
224 |
); |
225 |
|
226 |
oTest.fnTest( |
227 |
"Error when property missing on deep individual get (no default content)", |
228 |
function () { |
229 |
oSession.fnRestore(); |
230 |
test = false; |
231 |
|
232 |
try { |
233 |
$('#example').dataTable( { |
234 |
"aaData": [ |
235 |
{ |
236 |
"m": { "a": "a" }, |
237 |
"n": { "b": "b" }, |
238 |
"p": { "d": "d" }, |
239 |
"q": { "e": "e" } |
240 |
} |
241 |
], |
242 |
"aoColumns": [ |
243 |
{ "mDataProp": "m.a" }, |
244 |
{ "mDataProp": "n.b" }, |
245 |
{ "mDataProp": "o.c" }, |
246 |
{ "mDataProp": "p.d" }, |
247 |
{ "mDataProp": "q.e" } |
248 |
] |
249 |
} ); |
250 |
} catch (e) { |
251 |
test = true; |
252 |
} |
253 |
}, |
254 |
function () { return test; } |
255 |
); |
256 |
|
257 |
oTest.fnTest( |
258 |
"Default content used for missing prop on deep individual get and no error", |
259 |
function () { |
260 |
oSession.fnRestore(); |
261 |
|
262 |
$('#example').dataTable( { |
263 |
"aaData": [ |
264 |
{ |
265 |
"m": { "a": "a" }, |
266 |
"n": { "b": "b" }, |
267 |
"p": { "d": "d" }, |
268 |
"q": { "e": "e" } |
269 |
} |
270 |
], |
271 |
"aoColumns": [ |
272 |
{ "mDataProp": "m.a" }, |
273 |
{ "mDataProp": "n.b" }, |
274 |
{ "mDataProp": "o.c", "sDefaultContent": "test" }, |
275 |
{ "mDataProp": "p.d" }, |
276 |
{ "mDataProp": "q.e" } |
277 |
] |
278 |
} ); |
279 |
}, |
280 |
function () { return $('#example tbody td:eq(2)').html() === "test"; } |
281 |
); |
282 |
|
283 |
|
284 |
oTest.fnComplete(); |
285 |
} ); |