1 |
// DATA_TEMPLATE: empty_table |
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 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
14 |
"aoColumns": [ |
15 |
{ "mData": "engine" }, |
16 |
{ "mData": "browser" }, |
17 |
{ "mData": "platform" }, |
18 |
{ "mData": "version" }, |
19 |
{ "mData": "grade" } |
20 |
] |
21 |
} ); |
22 |
var oSettings = oTable.fnSettings(); |
23 |
|
24 |
oTest.fnWaitTest( |
25 |
"Auto width is enabled by default", |
26 |
null, |
27 |
function () { return oSettings.oFeatures.bAutoWidth; } |
28 |
); |
29 |
|
30 |
oTest.fnWaitTest( |
31 |
"First column has a width assigned to it", |
32 |
null, |
33 |
function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); } |
34 |
); |
35 |
|
36 |
/* |
37 |
This would seem like a better test - but there appear to be difficulties with tables |
38 |
which are bigger (calculated) than there is actually room for. I suspect this is actually |
39 |
a bug in datatables |
40 |
oTest.fnWaitTest( |
41 |
"Check column widths on first page match second page", |
42 |
null, |
43 |
function () { |
44 |
var anThs = $('#example thead th'); |
45 |
var a0 = anThs[0].offsetWidth; |
46 |
var a1 = anThs[1].offsetWidth; |
47 |
var a2 = anThs[2].offsetWidth; |
48 |
var a3 = anThs[3].offsetWidth; |
49 |
var a4 = anThs[4].offsetWidth; |
50 |
$('#example_next').click(); |
51 |
var b0 = anThs[0].offsetWidth; |
52 |
var b1 = anThs[1].offsetWidth; |
53 |
var b2 = anThs[2].offsetWidth; |
54 |
var b3 = anThs[3].offsetWidth; |
55 |
var b4 = anThs[4].offsetWidth; |
56 |
console.log( a0, b0, a1, b1, a2, b2, a3, b3 ); |
57 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
58 |
return true; |
59 |
else |
60 |
return false; |
61 |
} |
62 |
); |
63 |
|
64 |
oTest.fnWaitTest( |
65 |
"Check column widths on second page match thid page", |
66 |
null, |
67 |
function () { |
68 |
var anThs = $('#example thead th'); |
69 |
var a0 = anThs[0].offsetWidth; |
70 |
var a1 = anThs[1].offsetWidth; |
71 |
var a2 = anThs[2].offsetWidth; |
72 |
var a3 = anThs[3].offsetWidth; |
73 |
var a4 = anThs[4].offsetWidth; |
74 |
$('#example_next').click(); |
75 |
var b0 = anThs[0].offsetWidth; |
76 |
var b1 = anThs[1].offsetWidth; |
77 |
var b2 = anThs[2].offsetWidth; |
78 |
var b3 = anThs[3].offsetWidth; |
79 |
var b4 = anThs[4].offsetWidth; |
80 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
81 |
return true; |
82 |
else |
83 |
return false; |
84 |
} |
85 |
); |
86 |
*/ |
87 |
|
88 |
/* Check can disable */ |
89 |
oTest.fnWaitTest( |
90 |
"Auto width can be disabled", |
91 |
function () { |
92 |
oSession.fnRestore(); |
93 |
oTable = $('#example').dataTable( { |
94 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
95 |
"aoColumnDefs": [ |
96 |
{ "mData": "engine", "aTargets": [0] }, |
97 |
{ "mData": "browser", "aTargets": [1] }, |
98 |
{ "mData": "platform", "aTargets": [2] }, |
99 |
{ "mData": "version", "aTargets": [3] }, |
100 |
{ "mData": "grade", "aTargets": [4] } |
101 |
], |
102 |
"bAutoWidth": false |
103 |
} ); |
104 |
oSettings = oTable.fnSettings(); |
105 |
}, |
106 |
function () { return oSettings.oFeatures.bAutoWidth == false; } |
107 |
); |
108 |
|
109 |
oTest.fnWaitTest( |
110 |
"First column does not have a width assigned to it", |
111 |
null, |
112 |
function () { return $('#example thead th:eq(0)').attr('style') == null; } |
113 |
); |
114 |
|
115 |
/* |
116 |
oTest.fnWaitTest( |
117 |
"Check column widths on first page do not match second page", |
118 |
null, |
119 |
function () { |
120 |
var anThs = $('#example thead th'); |
121 |
var a0 = anThs[0].offsetWidth; |
122 |
var a1 = anThs[1].offsetWidth; |
123 |
var a2 = anThs[2].offsetWidth; |
124 |
var a3 = anThs[3].offsetWidth; |
125 |
var a4 = anThs[4].offsetWidth; |
126 |
$('#example_next').click(); |
127 |
var b0 = anThs[0].offsetWidth; |
128 |
var b1 = anThs[1].offsetWidth; |
129 |
var b2 = anThs[2].offsetWidth; |
130 |
var b3 = anThs[3].offsetWidth; |
131 |
var b4 = anThs[4].offsetWidth; |
132 |
if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 ) |
133 |
return false; |
134 |
else |
135 |
return true; |
136 |
} |
137 |
); |
138 |
*/ |
139 |
|
140 |
/* Enable makes no difference */ |
141 |
oTest.fnWaitTest( |
142 |
"Auto width enabled override", |
143 |
function () { |
144 |
oSession.fnRestore(); |
145 |
oTable = $('#example').dataTable( { |
146 |
"sAjaxSource": "../../../examples/ajax/sources/objects.txt", |
147 |
"aoColumnDefs": [ |
148 |
{ "mData": "engine", "aTargets": [0] }, |
149 |
{ "mData": "browser", "aTargets": [1] }, |
150 |
{ "mData": "platform", "aTargets": [2] }, |
151 |
{ "mData": "version", "aTargets": [3] }, |
152 |
{ "mData": "grade", "aTargets": [4] } |
153 |
], |
154 |
"bAutoWidth": true |
155 |
} ); |
156 |
oSettings = oTable.fnSettings(); |
157 |
}, |
158 |
function () { return oSettings.oFeatures.bAutoWidth; } |
159 |
); |
160 |
|
161 |
|
162 |
oTest.fnComplete(); |
163 |
} ); |