1 // DATA_TEMPLATE: empty_table
2 oTest.fnStart( "bAutoWidth" );
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)
10 $(document).ready( function () {
11 /* Check the default */
12 var oTable = $('#example').dataTable( {
13 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
15 { "mData": "engine" },
16 { "mData": "browser" },
17 { "mData": "platform" },
18 { "mData": "version" },
22 var oSettings = oTable.fnSettings();
25 "Auto width is enabled by default",
27 function () { return oSettings.oFeatures.bAutoWidth; }
31 "First column has a width assigned to it",
33 function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); }
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
41 "Check column widths on first page match second page",
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 )
65 "Check column widths on second page match thid page",
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 )
88 /* Check can disable */
90 "Auto width can be disabled",
93 oTable = $('#example').dataTable( {
94 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
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] }
104 oSettings = oTable.fnSettings();
106 function () { return oSettings.oFeatures.bAutoWidth == false; }
110 "First column does not have a width assigned to it",
112 function () { return $('#example thead th:eq(0)').attr('style') == null; }
117 "Check column widths on first page do not match second page",
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 )
140 /* Enable makes no difference */
142 "Auto width enabled override",
144 oSession.fnRestore();
145 oTable = $('#example').dataTable( {
146 "sAjaxSource": "../../../examples/ajax/sources/objects.txt",
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] }
156 oSettings = oTable.fnSettings();
158 function () { return oSettings.oFeatures.bAutoWidth; }