1 |
// DATA_TEMPLATE: dom_data |
2 |
oTest.fnStart( "aoColumns.sWidth" ); |
3 |
|
4 |
/* NOTE - we need to disable the auto width for the majority of these test in order to preform |
5 |
* these tests as the auto width will convert the width to a px value. We can do 'non-exact' tests |
6 |
* with auto width enabled however to ensure it scales columns as required |
7 |
*/ |
8 |
|
9 |
$(document).ready( function () { |
10 |
/* Check the default */ |
11 |
var oTable = $('#example').dataTable( { |
12 |
"bAutoWidth": false, |
13 |
"aoColumns": [ |
14 |
null, |
15 |
{ "sWidth": '40%' }, |
16 |
null, |
17 |
null, |
18 |
null |
19 |
] |
20 |
} ); |
21 |
var oSettings = oTable.fnSettings(); |
22 |
|
23 |
oTest.fnTest( |
24 |
"With auto width disabled the width for one column is appled", |
25 |
null, |
26 |
function () { return $('#example thead th:eq(1)')[0].style.width == "40%"; } |
27 |
); |
28 |
|
29 |
oTest.fnTest( |
30 |
"With auto width disabled the width for one column is appled", |
31 |
function () { |
32 |
oSession.fnRestore(); |
33 |
oTable = $('#example').dataTable( { |
34 |
"bAutoWidth": false, |
35 |
"aoColumns": [ |
36 |
null, |
37 |
null, |
38 |
{ "sWidth": '20%' }, |
39 |
{ "sWidth": '30%' }, |
40 |
null |
41 |
] |
42 |
} ); |
43 |
}, |
44 |
function () { |
45 |
var bReturn = |
46 |
$('#example thead th:eq(2)')[0].style.width == "20%" && |
47 |
$('#example thead th:eq(3)')[0].style.width == "30%"; |
48 |
return bReturn; |
49 |
} |
50 |
); |
51 |
|
52 |
|
53 |
oTest.fnTest( |
54 |
"With auto width, it will make the smallest column the largest with percentage width given", |
55 |
function () { |
56 |
oSession.fnRestore(); |
57 |
oTable = $('#example').dataTable( { |
58 |
"aoColumns": [ |
59 |
null, |
60 |
null, |
61 |
null, |
62 |
{ "sWidth": '40%' }, |
63 |
null |
64 |
] |
65 |
} ); |
66 |
}, |
67 |
function () { |
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 |
|
75 |
if ( a3>a0 && a3>a1 && a3>a2 && a3>a4 ) |
76 |
return true; |
77 |
else |
78 |
return false; |
79 |
} |
80 |
); |
81 |
|
82 |
|
83 |
oTest.fnComplete(); |
84 |
} ); |