1 // DATA_TEMPLATE: js_data
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( {
15 var oSettings = oTable.fnSettings();
18 "Auto width is enabled by default",
20 function () { return oSettings.oFeatures.bAutoWidth; }
24 "First column has a width assigned to it",
26 function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); }
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
34 "Check column widths on first page match second page",
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 )
58 "Check column widths on second page match thid page",
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 )
81 /* Check can disable */
83 "Auto width can be disabled",
86 oTable = $('#example').dataTable( {
90 oSettings = oTable.fnSettings();
92 function () { return oSettings.oFeatures.bAutoWidth == false; }
96 "First column does not have a width assigned to it",
98 function () { return $('#example thead th:eq(0)').attr('style') == null; }
103 "Check column widths on first page do not match second page",
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 )
126 /* Enable makes no difference */
128 "Auto width enabled override",
130 oSession.fnRestore();
131 oTable = $('#example').dataTable( {
135 oSettings = oTable.fnSettings();
137 function () { return oSettings.oFeatures.bAutoWidth; }