1 |
// DATA_TEMPLATE: dom_data |
2 |
oTest.fnStart( "fnCreatedRow tests" ); |
3 |
|
4 |
$(document).ready( function () { |
5 |
var tmp = 0; |
6 |
|
7 |
$('#example').dataTable( { |
8 |
fnCreatedRow: function () { |
9 |
tmp++; |
10 |
} |
11 |
} ); |
12 |
|
13 |
oTest.fnTest( |
14 |
"Row created is called once for each row on init", |
15 |
null, |
16 |
function () { return tmp===57; } |
17 |
); |
18 |
|
19 |
oTest.fnTest( |
20 |
"Created isn't called back on other draws", |
21 |
function () { $('#example th:eq(1)').click(); }, |
22 |
function () { return tmp===57; } |
23 |
); |
24 |
|
25 |
oTest.fnTest( |
26 |
"Three arguments for the function", |
27 |
function () { |
28 |
oSession.fnRestore(); |
29 |
tmp = true; |
30 |
|
31 |
$('#example').dataTable( { |
32 |
fnCreatedRow: function () { |
33 |
if ( arguments.length !== 3 ) { |
34 |
tmp = false; |
35 |
} |
36 |
} |
37 |
} ); |
38 |
}, |
39 |
function () { return tmp; } |
40 |
); |
41 |
|
42 |
oTest.fnTest( |
43 |
"First argument is a TR element", |
44 |
function () { |
45 |
oSession.fnRestore(); |
46 |
tmp = true; |
47 |
|
48 |
$('#example').dataTable( { |
49 |
fnCreatedRow: function () { |
50 |
if ( arguments[0].nodeName !== "TR" ) { |
51 |
tmp = false; |
52 |
} |
53 |
} |
54 |
} ); |
55 |
}, |
56 |
function () { return tmp; } |
57 |
); |
58 |
|
59 |
oTest.fnTest( |
60 |
"Second argument is an array with 5 elements", |
61 |
function () { |
62 |
oSession.fnRestore(); |
63 |
tmp = true; |
64 |
|
65 |
$('#example').dataTable( { |
66 |
fnCreatedRow: function () { |
67 |
if ( arguments[1].length !== 5 ) { |
68 |
tmp = false; |
69 |
} |
70 |
} |
71 |
} ); |
72 |
}, |
73 |
function () { return tmp; } |
74 |
); |
75 |
|
76 |
oTest.fnTest( |
77 |
"Third argument is the data source for the row", |
78 |
function () { |
79 |
oSession.fnRestore(); |
80 |
tmp = true; |
81 |
|
82 |
$('#example').dataTable( { |
83 |
fnCreatedRow: function () { |
84 |
if ( arguments[1] !== this.fnSettings().aoData[ arguments[2] ]._aData ) { |
85 |
tmp = false; |
86 |
} |
87 |
} |
88 |
} ); |
89 |
}, |
90 |
function () { return tmp; } |
91 |
); |
92 |
|
93 |
oTest.fnTest( |
94 |
"TR element is tied to the correct data", |
95 |
function () { |
96 |
oSession.fnRestore(); |
97 |
tmp = false; |
98 |
|
99 |
$('#example').dataTable( { |
100 |
fnCreatedRow: function (tr, data, index) { |
101 |
if ( data[1] === "Firefox 1.0" ) { |
102 |
if ( $('td:eq(3)', tr).html() == "1.7" ) { |
103 |
tmp = true; |
104 |
} |
105 |
} |
106 |
} |
107 |
} ); |
108 |
}, |
109 |
function () { return tmp; } |
110 |
); |
111 |
|
112 |
|
113 |
|
114 |
oTest.fnComplete(); |
115 |
} ); |