[6286] | 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 | "bServerSide": true, |
---|
| 14 | "sAjaxSource": "../../../examples/examples_support/server_processing.php" |
---|
| 15 | } ); |
---|
| 16 | var oSettings = oTable.fnSettings(); |
---|
| 17 | |
---|
| 18 | oTest.fnWaitTest( |
---|
| 19 | "Auto width is enabled by default", |
---|
| 20 | null, |
---|
| 21 | function () { return oSettings.oFeatures.bAutoWidth; } |
---|
| 22 | ); |
---|
| 23 | |
---|
| 24 | oTest.fnWaitTest( |
---|
| 25 | "First column has a width assigned to it", |
---|
| 26 | null, |
---|
| 27 | function () { return $('#example thead th:eq(0)').attr('style').match(/width/i); } |
---|
| 28 | ); |
---|
| 29 | |
---|
| 30 | /* |
---|
| 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 |
---|
| 33 | a bug in datatables |
---|
| 34 | oTest.fnWaitTest( |
---|
| 35 | "Check column widths on first page match second page", |
---|
| 36 | null, |
---|
| 37 | function () { |
---|
| 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 ) |
---|
| 52 | return true; |
---|
| 53 | else |
---|
| 54 | return false; |
---|
| 55 | } |
---|
| 56 | ); |
---|
| 57 | |
---|
| 58 | oTest.fnWaitTest( |
---|
| 59 | "Check column widths on second page match thid page", |
---|
| 60 | null, |
---|
| 61 | function () { |
---|
| 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 ) |
---|
| 75 | return true; |
---|
| 76 | else |
---|
| 77 | return false; |
---|
| 78 | } |
---|
| 79 | ); |
---|
| 80 | */ |
---|
| 81 | |
---|
| 82 | /* Check can disable */ |
---|
| 83 | oTest.fnWaitTest( |
---|
| 84 | "Auto width can be disabled", |
---|
| 85 | function () { |
---|
| 86 | oSession.fnRestore(); |
---|
| 87 | oTable = $('#example').dataTable( { |
---|
| 88 | "bServerSide": true, |
---|
| 89 | "sAjaxSource": "../../../examples/examples_support/server_processing.php", |
---|
| 90 | "bAutoWidth": false |
---|
| 91 | } ); |
---|
| 92 | oSettings = oTable.fnSettings(); |
---|
| 93 | }, |
---|
| 94 | function () { return oSettings.oFeatures.bAutoWidth == false; } |
---|
| 95 | ); |
---|
| 96 | |
---|
| 97 | oTest.fnWaitTest( |
---|
| 98 | "First column does not have a width assigned to it", |
---|
| 99 | null, |
---|
| 100 | function () { return $('#example thead th:eq(0)').attr('style') == null; } |
---|
| 101 | ); |
---|
| 102 | |
---|
| 103 | /* |
---|
| 104 | oTest.fnWaitTest( |
---|
| 105 | "Check column widths on first page do not match second page", |
---|
| 106 | null, |
---|
| 107 | function () { |
---|
| 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 ) |
---|
| 121 | return false; |
---|
| 122 | else |
---|
| 123 | return true; |
---|
| 124 | } |
---|
| 125 | ); |
---|
| 126 | */ |
---|
| 127 | |
---|
| 128 | /* Enable makes no difference */ |
---|
| 129 | oTest.fnWaitTest( |
---|
| 130 | "Auto width enabled override", |
---|
| 131 | function () { |
---|
| 132 | oSession.fnRestore(); |
---|
| 133 | oTable = $('#example').dataTable( { |
---|
| 134 | "bServerSide": true, |
---|
| 135 | "sAjaxSource": "../../../examples/examples_support/server_processing.php", |
---|
| 136 | "bAutoWidth": true |
---|
| 137 | } ); |
---|
| 138 | oSettings = oTable.fnSettings(); |
---|
| 139 | }, |
---|
| 140 | function () { return oSettings.oFeatures.bAutoWidth; } |
---|
| 141 | ); |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | oTest.fnComplete(); |
---|
| 145 | } ); |
---|