1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
describe('columnDefs option', function() {
dt.libs({
js: ['jquery', 'datatables'],
css: ['datatables']
});
describe('Check the defaults', function() {
dt.html('basic');
it('Default should be null', function() {
$('#example').dataTable();
expect($.fn.dataTable.defaults.aoColumnDefs).toBe(null);
});
dt.html('basic');
it(" '_all' targets all columns. ", function() {
$('#example').dataTable({
columnDefs: [{ targets: '_all', visible: false }]
});
expect($('#example thead').find('th').length).toBe(0);
});
dt.html('basic');
it('_all with other targets first', function() {
$('#example').dataTable({
columnDefs: [{ targets: [0], visible: true }, { targets: '_all', visible: false }]
});
expect($('#example thead').find('th').length).toBe(1);
});
dt.html('basic');
it('_all with other targets after', function() {
$('#example').dataTable({
columnDefs: [{ targets: '_all', visible: false }, { targets: [0], visible: true }]
});
expect($('#example thead').find('th').length).toBe(0);
});
dt.html('basic');
it('Select 1 column not in an array', function() {
$('#example').dataTable({
columnDefs: [{ targets: 0, visible: false }]
});
expect($('#example thead').find('th').length).toBe(5);
expect($('#example thead th:eq(0)').text()).toBe('Position');
});
dt.html('basic');
it('Select 1 column using array', function() {
$('#example').dataTable({
columnDefs: [{ targets: [0], visible: false }]
});
expect($('#example thead').find('th').length).toBe(5);
expect($('#example thead th:eq(0)').text()).toBe('Position');
});
dt.html('basic');
it('Select 2 columns using array', function() {
$('#example').dataTable({
columnDefs: [{ targets: [0, 1], visible: false }]
});
expect($('#example thead').find('th').length).toBe(4);
expect($('#example thead th:eq(0)').text()).toBe('Office');
});
dt.html('basic');
it('Use negative int to select last column', function() {
$('#example').dataTable({
columnDefs: [{ targets: [-1], visible: false }]
});
expect($('#example thead').find('th').length).toBe(5);
expect($('#example thead th:eq(-1)').text()).toBe('Start date');
});
dt.html('basic');
it('Use negative int to select multiple columns', function() {
$('#example').dataTable({
columnDefs: [{ targets: [-1, -2], visible: false }]
});
expect($('#example thead').find('th').length).toBe(4);
expect($('#example thead th:eq(-1)').text()).toBe('Age');
});
dt.html('basic');
it('Mixed negative and positive ints to select columns - remove first and last columns', function() {
$('#example').dataTable({
columnDefs: [{ targets: [0, -1], visible: false }]
});
expect($('#example thead').find('th').length).toBe(4);
expect($('#example thead th:eq(0)').text()).toBe('Position');
expect($('#example thead th:eq(-1)').text()).toBe('Start date');
});
dt.html('basic');
it('Specify class', function() {
$('#example thead th:eq(0)').addClass('test1');
$('#example').dataTable({
columnDefs: [{ targets: 'test1', visible: false }]
});
expect($('#example thead').find('th').length).toBe(5);
expect($('#example thead th:eq(0)').text()).toBe('Position');
});
dt.html('basic');
it('Specify multiple classes', function() {
$('#example thead th:eq(0)').addClass('test1');
$('#example thead th:eq(5)').addClass('test2');
$('#example').dataTable({
columnDefs: [{ targets: ['test1', 'test2'], visible: false }]
});
expect($('#example thead').find('th').length).toBe(4);
expect($('#example thead th:eq(0)').text()).toBe('Position');
expect($('#example thead th:eq(-1)').text()).toBe('Start date');
});
dt.html('basic');
it('Mix class and integer', function() {
$('#example thead th:eq(0)').addClass('test1');
$('#example').dataTable({
columnDefs: [{ targets: [-1, 'test1'], visible: false }]
});
expect($('#example thead').find('th').length).toBe(4);
expect($('#example thead th:eq(0)').text()).toBe('Position');
expect($('#example thead th:eq(-1)').text()).toBe('Start date');
});
});
describe('Check the defaults', function() {
dt.html('basic');
it('Same column referenced twice', function() {
let table = $('#example').DataTable({
columnDefs: [{ targets: 0, title: 'fred' }, { targets: 0, data: null, defaultContent: 'stan' }]
});
expect($('#example thead th:eq(0)').text()).toBe('fred');
expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('stan');
});
dt.html('basic');
it('Same column referenced twice with conflict', function() {
let table = $('#example').DataTable({
columnDefs: [
{ targets: 0, title: 'fred' },
{ targets: 0, title: 'stan' },
{ targets: 0, data: null, defaultContent: 'stan' }
]
});
expect($('#example thead th:eq(0)').text()).toBe('fred');
expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('stan');
});
dt.html('basic');
it('Same column referenced twice with conflict with other columns', function() {
let table = $('#example').DataTable({
columnDefs: [
{ targets: 0, title: 'fred' },
{ targets: [0, 1], title: 'stan' },
{ targets: 0, data: null, defaultContent: 'stan' }
]
});
expect($('#example thead th:eq(0)').text()).toBe('fred');
expect($('#example thead th:eq(1)').text()).toBe('stan');
expect($('#example tbody tr:eq(0) td:eq(0)').text()).toBe('stan');
});
});
});
|