1 // DATA_TEMPLATE: complex_header_2
2 oTest.fnStart( "fnSetColumnVis with complex headers" );
4 $(document).ready( function () {
5 /* Check the default */
6 var oTable = $('#example').dataTable();
7 var oSettings = oTable.fnSettings();
10 "All columns are visible by default",
12 function () { return $('#example tbody tr:eq(0) td').length == 5; }
16 "Hide the first column",
18 $('#example').dataTable().fnSetColumnVis( 0, false );
20 function () { return $('#example tbody tr:eq(0) td').length == 4; }
24 "First cell is '2' - first column hidden",
26 function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "2"; }
30 "First cell has colspan of 3",
32 function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('colspan') == 3; }
36 "First cell has rowspan of 2",
38 function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('rowspan') == 2; }
42 "First cell in last column is '11'",
44 function () { return $('#example thead tr:eq(4) th:eq(0)').html() == 11; }
48 "First cell in last column has been truncated to one column",
50 function () { return $('#example thead tr:eq(4) th:eq(0)')[0].getAttribute('colspan') == 1; }
55 "Hide the second column",
57 $('#example').dataTable().fnSetColumnVis( 0, true );
58 $('#example').dataTable().fnSetColumnVis( 1, false );
60 function () { return $('#example tbody tr:eq(0) td').length == 4; }
64 "First cell is '1' - second column hidden",
66 function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "1"; }
70 "Second cell is '2' - second column hidden",
72 function () { return $('#example thead tr:eq(0) th:eq(1)').html() == "2"; }
76 "First cell in fourth row is '10' (visibly the first) - second column hidden",
78 function () { return $('#example thead tr:eq(3) th:eq(0)').html() == "10"; }
82 "First cell has colspan of 1",
84 function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('colspan') == 1; }
88 "Second cell has colspan of 2",
90 function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('colspan') == 2; }
94 "First cell has rowspan of 1",
96 function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('rowspan') == 1; }
100 "Second cell has rowspan of 2",
102 function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('rowspan') == 2; }
106 "First cell in last column is '11'",
108 function () { return $('#example thead tr:eq(4) th:eq(0)').html() == 11; }
112 "First cell in last column has been truncated to one column",
114 function () { return $('#example thead tr:eq(4) th:eq(0)')[0].getAttribute('colspan') == 1; }
119 "Hide the first two columns",
121 $('#example').dataTable().fnSetColumnVis( 0, false );
122 $('#example').dataTable().fnSetColumnVis( 1, false );
124 function () { return $('#example tbody tr:eq(0) td').length == 3; }
128 "First cell is '2' - first two columns hidden",
130 function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "2"; }
134 "Second cell is '3' - first two columns hidden",
136 function () { return $('#example thead tr:eq(0) th:eq(1)').html() == "3"; }
140 "First cell in third row is '6' - first two columns hidden",
142 function () { return $('#example thead tr:eq(2) th:eq(0)').html() == "6"; }
146 "First cell has colspan of 2",
148 function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('colspan') == 2; }
152 "First cell has rowspan of 2",
154 function () { return $('#example thead tr:eq(0) th:eq(0)')[0].getAttribute('rowspan') == 2; }
158 "Second cell has rowspan of 1",
160 function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('rowspan') == 1; }
164 "First cell in last column is '12'",
166 function () { return $('#example thead tr:eq(4) th:eq(0)').html() == 12; }
171 "Hide the third column",
173 $('#example').dataTable().fnSetColumnVis( 0, true );
174 $('#example').dataTable().fnSetColumnVis( 1, true );
175 $('#example').dataTable().fnSetColumnVis( 2, false );
177 function () { return $('#example tbody tr:eq(0) td').length == 4; }
181 "First cell is '1' - third column hidden",
183 function () { return $('#example thead tr:eq(0) th:eq(0)').html() == "1"; }
187 "Second cell is '2' - third column hidden",
189 function () { return $('#example thead tr:eq(0) th:eq(1)').html() == "2"; }
193 "First cell (visible second) in third row is '6' - third column hidden",
195 function () { return $('#example thead tr:eq(2) th:eq(0)').html() == "6"; }
199 "Second cell has colspan of 2",
201 function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('colspan') == 2; }
205 "Second cell has rowspan of 2",
207 function () { return $('#example thead tr:eq(0) th:eq(1)')[0].getAttribute('rowspan') == 2; }
211 "Third row first cell (second visible) colspan is 1",
213 function () { return $('#example thead tr:eq(2) th:eq(0)')[0].getAttribute('colspan') == 1; }
217 "Third row second cell (third visible) value is 7",
219 function () { return $('#example thead tr:eq(2) th:eq(1)').html() == "7"; }
223 "Third row second cell (third visible) colspan is 1",
225 function () { return $('#example thead tr:eq(2) th:eq(1)')[0].getAttribute('colspan') == 1; }
229 "Third row second cell (third visible) rowspan is 3",
231 function () { return $('#example thead tr:eq(2) th:eq(1)')[0].getAttribute('rowspan') == 3; }