1 // DATA_TEMPLATE: dom_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();
13 var oSettings = oTable.fnSettings();
16 "Auto width is enabled by default",
18 function () { return oSettings.oFeatures.bAutoWidth; }
22 "First column has a width assigned to it",
24 function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); }
28 This would seem like a better test - but there appear to be difficulties with tables
29 which are bigger (calculated) than there is actually room for. I suspect this is actually
32 "Check column widths on first page match second page",
35 var anThs = $('#example thead th');
36 var a0 = anThs[0].offsetWidth;
37 var a1 = anThs[1].offsetWidth;
38 var a2 = anThs[2].offsetWidth;
39 var a3 = anThs[3].offsetWidth;
40 var a4 = anThs[4].offsetWidth;
41 $('#example_next').click();
42 var b0 = anThs[0].offsetWidth;
43 var b1 = anThs[1].offsetWidth;
44 var b2 = anThs[2].offsetWidth;
45 var b3 = anThs[3].offsetWidth;
46 var b4 = anThs[4].offsetWidth;
47 console.log( a0, b0, a1, b1, a2, b2, a3, b3 );
48 if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 )
56 "Check column widths on second page match thid page",
59 var anThs = $('#example thead th');
60 var a0 = anThs[0].offsetWidth;
61 var a1 = anThs[1].offsetWidth;
62 var a2 = anThs[2].offsetWidth;
63 var a3 = anThs[3].offsetWidth;
64 var a4 = anThs[4].offsetWidth;
65 $('#example_next').click();
66 var b0 = anThs[0].offsetWidth;
67 var b1 = anThs[1].offsetWidth;
68 var b2 = anThs[2].offsetWidth;
69 var b3 = anThs[3].offsetWidth;
70 var b4 = anThs[4].offsetWidth;
71 if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 )
79 /* Check can disable */
81 "Auto width can be disabled",
84 oTable = $('#example').dataTable( {
87 oSettings = oTable.fnSettings();
89 function () { return oSettings.oFeatures.bAutoWidth == false; }
93 "First column does not have a width assigned to it",
95 function () { return $('#example thead th:eq(0)').attr('style') == null; }
100 "Check column widths on first page do not match second page",
103 var anThs = $('#example thead th');
104 var a0 = anThs[0].offsetWidth;
105 var a1 = anThs[1].offsetWidth;
106 var a2 = anThs[2].offsetWidth;
107 var a3 = anThs[3].offsetWidth;
108 var a4 = anThs[4].offsetWidth;
109 $('#example_next').click();
110 var b0 = anThs[0].offsetWidth;
111 var b1 = anThs[1].offsetWidth;
112 var b2 = anThs[2].offsetWidth;
113 var b3 = anThs[3].offsetWidth;
114 var b4 = anThs[4].offsetWidth;
115 if ( a0==b0 && a1==b1 && a2==b2 && a3==b3 )
123 /* Enable makes no difference */
125 "Auto width enabled override",
127 oSession.fnRestore();
128 oTable = $('#example').dataTable( {
131 oSettings = oTable.fnSettings();
133 function () { return oSettings.oFeatures.bAutoWidth; }