File: fnSetColumnVis2.js

package info (click to toggle)
datatables.js 1.10.21%2Bdfsg-2%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,604 kB
  • sloc: javascript: 64,254; xml: 10,441; php: 4,623; sh: 523; makefile: 21
file content (236 lines) | stat: -rwxr-xr-x 6,303 bytes parent folder | download | duplicates (6)
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
// DATA_TEMPLATE: complex_header_2
oTest.fnStart( "fnSetColumnVis with complex headers" );

$(document).ready( function () {
	/* Check the default */
	var oTable = $('#example').dataTable();
	var oSettings = oTable.fnSettings();
	
	oTest.fnTest( 
		"All columns are visible by default",
		null,
		function () { return $('#example tbody tr:eq(0) td').length == 5; }
	);
	
	oTest.fnTest( 
		"Hide the first column",
		function () {
			$('#example').dataTable().fnSetColumnVis( 0, false );
		},
		function () { return $('#example tbody tr:eq(0) td').length == 4; }
	);
	
	oTest.fnTest(
		"First cell is '2' - first column hidden",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "2"; }
	);
	
	oTest.fnTest(
		"First cell has colspan of 3",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('colspan') == 3; }
	);
	
	oTest.fnTest(
		"First cell has rowspan of 2",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('rowspan') == 2; }
	);
	
	oTest.fnTest(
		"First cell in last column is '11'",
		null,
		function () { return $('#example thead tr:eq(4) th:eq(0)').html() == 11; }
	);
	
	oTest.fnTest(
		"First cell in last column has been truncated to one column",
		null,
		function () { return $('#example thead tr:eq(4) th:eq(0)')[0].getAttribute('colspan') == 1; }
	);
	
	
	oTest.fnTest( 
		"Hide the second column",
		function () {
			$('#example').dataTable().fnSetColumnVis( 0, true );
			$('#example').dataTable().fnSetColumnVis( 1, false );
		},
		function () { return $('#example tbody tr:eq(0) td').length == 4; }
	);
	
	oTest.fnTest(
		"First cell is '1' - second column hidden",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "1"; }
	);
	
	oTest.fnTest(
		"Second cell is '2' - second column hidden",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)').html() == "2"; }
	);
	
	oTest.fnTest(
		"First cell in fourth row is '10' (visibly the first) - second column hidden",
		null,
		function () { return $('#example thead tr:eq(3) th:eq(0)').html() == "10"; }
	);
	
	oTest.fnTest(
		"First cell has colspan of 1",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('colspan') == 1; }
	);
	
	oTest.fnTest(
		"Second cell has colspan of 2",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('colspan') == 2; }
	);
	
	oTest.fnTest(
		"First cell has rowspan of 1",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('rowspan') == 1; }
	);
	
	oTest.fnTest(
		"Second cell has rowspan of 2",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('rowspan') == 2; }
	);
	
	oTest.fnTest(
		"First cell in last column is '11'",
		null,
		function () { return $('#example thead tr:eq(4) th:eq(0)').html() == 11; }
	);
	
	oTest.fnTest(
		"First cell in last column has been truncated to one column",
		null,
		function () { return $('#example thead tr:eq(4) th:eq(0)')[0].getAttribute('colspan') == 1; }
	);
	
	
	oTest.fnTest( 
		"Hide the first two columns",
		function () {
			$('#example').dataTable().fnSetColumnVis( 0, false );
			$('#example').dataTable().fnSetColumnVis( 1, false );
		},
		function () { return $('#example tbody tr:eq(0) td').length == 3; }
	);
	
	oTest.fnTest(
		"First cell is '2' - first two columns hidden",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "2"; }
	);
	
	oTest.fnTest(
		"Second cell is '3' - first two columns hidden",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)').html() == "3"; }
	);
	
	oTest.fnTest(
		"First cell in third row is '6' - first two columns hidden",
		null,
		function () { return $('#example thead tr:eq(2) th:eq(0)').html() == "6"; }
	);
	
	oTest.fnTest(
		"First cell has colspan of 2",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('colspan') == 2; }
	);
	
	oTest.fnTest(
		"First cell has rowspan of 2",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('rowspan') == 2; }
	);
	
	oTest.fnTest(
		"Second cell has rowspan of 1",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('rowspan') == 1; }
	);
	
	oTest.fnTest(
		"First cell in last column is '12'",
		null,
		function () { return $('#example thead tr:eq(4) th:eq(0)').html() == 12; }
	);
	
	
	oTest.fnTest( 
		"Hide the third column",
		function () {
			$('#example').dataTable().fnSetColumnVis( 0, true );
			$('#example').dataTable().fnSetColumnVis( 1, true );
			$('#example').dataTable().fnSetColumnVis( 2, false );
		},
		function () { return $('#example tbody tr:eq(0) td').length == 4; }
	);
	
	oTest.fnTest(
		"First cell is '1' - third column hidden",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "1"; }
	);
	
	oTest.fnTest(
		"Second cell is '2' - third column hidden",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)').html() == "2"; }
	);
	
	oTest.fnTest(
		"First cell (visible second) in third row is '6' - third column hidden",
		null,
		function () { return $('#example thead tr:eq(2) th:eq(0)').html() == "6"; }
	);
	
	oTest.fnTest(
		"Second cell has colspan of 2",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('colspan') == 2; }
	);
	
	oTest.fnTest(
		"Second cell has rowspan of 2",
		null,
		function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('rowspan') == 2; }
	);
	
	oTest.fnTest(
		"Third row first cell (second visible) colspan is 1",
		null,
		function () { return $('#example thead tr:eq(2) th:eq(0)')[0].getAttribute('colspan') == 1; }
	);
	
	oTest.fnTest(
		"Third row second cell (third visible) value is 7",
		null,
		function () { return $('#example thead tr:eq(2) th:eq(1)').html() == "7"; }
	);
	
	oTest.fnTest(
		"Third row second cell (third visible) colspan is 1",
		null,
		function () { return $('#example thead tr:eq(2) th:eq(1)')[0].getAttribute('colspan') == 1; }
	);
	
	oTest.fnTest(
		"Third row second cell (third visible) rowspan is 3",
		null,
		function () { return $('#example thead tr:eq(2) th:eq(1)')[0].getAttribute('rowspan') == 3; }
	);
	
	
	oTest.fnComplete();
} );