1 |
// DATA_TEMPLATE: js_data |
2 |
oTest.fnStart( "bAutoWidth" ); |
3 |
|
4 |
/* It's actually a little tricky to test this. We can't test absolute numbers because |
5 |
* different browsers and different platforms will render the width of the columns slightly |
6 |
* differently. However, we certainly can test the principle of what should happen (column |
7 |
* width doesn't change over pages) |
8 |
*/ |
9 |
|
10 |
$(document).ready( function () { |
11 |
/* Check the default */ |
12 |
var oTable = $('#example').dataTable( { |
13 |
"aaData": gaaData |
14 |
} ); |
15 |
var oSettings = oTable.fnSettings(); |
16 |
|
17 |
oTest.fnTest( |
18 |
"Auto width is enabled by default", |
19 |
null, |
20 |
function () { return oSettings.oFeatures.bAutoWidth; } |
21 |
); |
22 |
|
23 |
oTest.fnTest( |
24 |
"First column has a width assigned to it", |
25 |
null, |
26 |
function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); } |
27 |
); |
28 |
|
29 |
/* |
30 |
This would seem like a better test - but there appear to be difficulties with tables |
31 |
which are bigger (calculated) than there is actually room for. I suspect this is actually |
32 |
a bug in datatables |
33 |
oTest.fnTest( |
34 |
"Check column widths on first page match second page", |
35 |
null, |
36 |
function () { |
37 |
var anThs = $('#example thead th'); |
38 |
var a0 = anThs[0].offsetWidth; |
39 |
var a1 = anThs[1].offsetWidth; |
40 |
var a2 = anThs[2].offsetWidth; |
41 |
var a3 = anThs[3].offsetWidth; |
42 |
var a4 = anThs[4].offsetWidth; |
43 |
$('#example_next').click(); |
44 |
var b0 = anThs[0].offsetWidth; |
45 |
var b1 = anThs[1].offsetWidth; |
46 |
var b2 = anThs[2].offsetWidth; |
47 |
var b3 = anThs[3].offsetWidth; |
48 |
var b4 = anThs[4].offsetWidth; |
49 |
console.log( a0, b0, a1, b1, a2, b2, a3, b3 ); |
50 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
51 |
return true; |
52 |
else |
53 |
return false; |
54 |
} |
55 |
); |
56 |
|
57 |
oTest.fnTest( |
58 |
"Check column widths on second page match thid page", |
59 |
null, |
60 |
function () { |
61 |
var anThs = $('#example thead th'); |
62 |
var a0 = anThs[0].offsetWidth; |
63 |
var a1 = anThs[1].offsetWidth; |
64 |
var a2 = anThs[2].offsetWidth; |
65 |
var a3 = anThs[3].offsetWidth; |
66 |
var a4 = anThs[4].offsetWidth; |
67 |
$('#example_next').click(); |
68 |
var b0 = anThs[0].offsetWidth; |
69 |
var b1 = anThs[1].offsetWidth; |
70 |
var b2 = anThs[2].offsetWidth; |
71 |
var b3 = anThs[3].offsetWidth; |
72 |
var b4 = anThs[4].offsetWidth; |
73 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
74 |
return true; |
75 |
else |
76 |
return false; |
77 |
} |
78 |
); |
79 |
*/ |
80 |
|
81 |
/* Check can disable */ |
82 |
oTest.fnTest( |
83 |
"Auto width can be disabled", |
84 |
function () { |
85 |
oSession.fnRestore(); |
86 |
oTable = $('#example').dataTable( { |
87 |
"aaData": gaaData, |
88 |
"bAutoWidth": false |
89 |
} ); |
90 |
oSettings = oTable.fnSettings(); |
91 |
}, |
92 |
function () { return oSettings.oFeatures.bAutoWidth == false; } |
93 |
); |
94 |
|
95 |
oTest.fnTest( |
96 |
"First column does not have a width assigned to it", |
97 |
null, |
98 |
function () { return $('#example thead th:eq(0)').attr('style') == null; } |
99 |
); |
100 |
|
101 |
/* |
102 |
oTest.fnTest( |
103 |
"Check column widths on first page do not match second page", |
104 |
null, |
105 |
function () { |
106 |
var anThs = $('#example thead th'); |
107 |
var a0 = anThs[0].offsetWidth; |
108 |
var a1 = anThs[1].offsetWidth; |
109 |
var a2 = anThs[2].offsetWidth; |
110 |
var a3 = anThs[3].offsetWidth; |
111 |
var a4 = anThs[4].offsetWidth; |
112 |
$('#example_next').click(); |
113 |
var b0 = anThs[0].offsetWidth; |
114 |
var b1 = anThs[1].offsetWidth; |
115 |
var b2 = anThs[2].offsetWidth; |
116 |
var b3 = anThs[3].offsetWidth; |
117 |
var b4 = anThs[4].offsetWidth; |
118 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
119 |
return false; |
120 |
else |
121 |
return true; |
122 |
} |
123 |
); |
124 |
*/ |
125 |
|
126 |
/* Enable makes no difference */ |
127 |
oTest.fnTest( |
128 |
"Auto width enabled override", |
129 |
function () { |
130 |
oSession.fnRestore(); |
131 |
oTable = $('#example').dataTable( { |
132 |
"aaData": gaaData, |
133 |
"bAutoWidth": true |
134 |
} ); |
135 |
oSettings = oTable.fnSettings(); |
136 |
}, |
137 |
function () { return oSettings.oFeatures.bAutoWidth; } |
138 |
); |
139 |
|
140 |
|
141 |
oTest.fnComplete(); |
142 |
} ); |