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/arrays.txt",
16 var oSettings = oTable.fnSettings();
19 "Auto width is enabled by default",
21 function () { return oSettings.oFeatures.bAutoWidth; }
25 "First column has a width assigned to it",
27 function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); }
31 This would seem like a better test - but there appear to be difficulties with tables
32 which are bigger (calculated) than there is actually room for. I suspect this is actually
35 "Check column widths on first page match second page",
38 var anThs = $('#example thead th');
39 var a0 = anThs[0].offsetWidth;
40 var a1 = anThs[1].offsetWidth;
41 var a2 = anThs[2].offsetWidth;
42 var a3 = anThs[3].offsetWidth;
43 var a4 = anThs[4].offsetWidth;
44 $('#example_next').click();
45 var b0 = anThs[0].offsetWidth;
46 var b1 = anThs[1].offsetWidth;
47 var b2 = anThs[2].offsetWidth;
48 var b3 = anThs[3].offsetWidth;
49 var b4 = anThs[4].offsetWidth;
50 console.log( a0, b0, a1, b1, a2, b2, a3, b3 );
51 if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 )
59 "Check column widths on second page match thid page",
62 var anThs = $('#example thead th');
63 var a0 = anThs[0].offsetWidth;
64 var a1 = anThs[1].offsetWidth;
65 var a2 = anThs[2].offsetWidth;
66 var a3 = anThs[3].offsetWidth;
67 var a4 = anThs[4].offsetWidth;
68 $('#example_next').click();
69 var b0 = anThs[0].offsetWidth;
70 var b1 = anThs[1].offsetWidth;
71 var b2 = anThs[2].offsetWidth;
72 var b3 = anThs[3].offsetWidth;
73 var b4 = anThs[4].offsetWidth;
74 if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 )
82 /* Check can disable */
84 "Auto width can be disabled",
87 oTable = $('#example').dataTable( {
88 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
92 oSettings = oTable.fnSettings();
94 function () { return oSettings.oFeatures.bAutoWidth == false; }
98 "First column does not have a width assigned to it",
100 function () { return $('#example thead th:eq(0)').attr('style') == null; }
105 "Check column widths on first page do not match second page",
108 var anThs = $('#example thead th');
109 var a0 = anThs[0].offsetWidth;
110 var a1 = anThs[1].offsetWidth;
111 var a2 = anThs[2].offsetWidth;
112 var a3 = anThs[3].offsetWidth;
113 var a4 = anThs[4].offsetWidth;
114 $('#example_next').click();
115 var b0 = anThs[0].offsetWidth;
116 var b1 = anThs[1].offsetWidth;
117 var b2 = anThs[2].offsetWidth;
118 var b3 = anThs[3].offsetWidth;
119 var b4 = anThs[4].offsetWidth;
120 if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 )
128 /* Enable makes no difference */
130 "Auto width enabled override",
132 oSession.fnRestore();
133 oTable = $('#example').dataTable( {
134 "sAjaxSource": "../../../examples/ajax/sources/arrays.txt",
135 "bDeferRender": true,
138 oSettings = oTable.fnSettings();
140 function () { return oSettings.oFeatures.bAutoWidth; }